1. Download the latest version of MySQL5.7
1. Official website address
https://downloads.mysql.com/archives/community/
2. Download the latest version of MySQL5.7
Download the installation package shown in the figure below:
Two, install MySQL5.7
1. Unzip
Unzip the downloaded compressed package just now and match the directory C:\software\mysql-5.7.41, (you can switch the path at will).
2. Create a new file my.ini
Create a new file in the C:\software\mysql-5.7.41 directory my.ini
. The content of the file is as follows. Note that basedir
and datadir
is the installation directory. The content is as follows:
[Client]
#设置3306端口
port = 3306
[mysqld]
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=C:/software/mysql-5.7.41
# 设置mysql数据库的数据的存放目录
datadir=C:/software/mysql-5.7.41/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
character_set_server = utf8
lower_case_table_names = 1
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
3. System environment variable settings
(1) Right click on This Computer and select Properties
(2) Select Advanced System Settings
(3) Select environment variables
Note: You can also search for "environment variables" in the search box of Windows 11, and choose to edit the system environment variables
(4) Add system environment variables
系统变量
Create a new variable inside MYSQL_HOME
, and enter the path of the MySQL folder after decompression.
(5) Edit system variablespath
Find the variable 系统变量内
in it Path
, double-click to open it, and finally add %MYSQL_HOME%\bin
4. Installation command
(1) Open cmd as an administrator
(2) Switch to the C:\software\mysql-5.7.41\bin folder
(3) Enter the following statement to create a new data folder and create a default database
mysqld --initialize-insecure --user=mysql
(4) Installation service
mysqld -install
Note: the first installation will show "Service successfully installed"
If it has already been installed, it will display "The service already exists!", then you need to remove the service:
mysqld -remove
3. Enter and configure MySQL
1. Start the MySQL service
Enter the following command in cmd:
net start mysql
2. Login
#输入登录语句:-u 指的是登录的用户名,-p 是密码,因为是默认安装的数据库,此时密码为空,回车即可。
mysql -u root -p
3. Set password
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
flush privileges;
exit;
Note: Because MySQL has established a default database, the user name is root, and the password is empty, so in order to avoid login problems later, change the password first after login. The new_password part is your new password.(注意密码在单引号内部:'password')
4. Stop the MySQL service
net stop mysql
5. Enable remote access to mysql
Execute the following command to enable remote access restriction (note: the IP enabled by the following command is 192.168.0.1, if you want to enable all, use % instead of IP):
grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;
Then enter the following two lines of commands
flush privileges;
exit;