Due to the long-term use of the old version 5.5 and the mariadb branch version on Windows devices. 5.7 is rarely used, so occasionally it takes a long time to install 5.7 to test some troubles. Download the record here for easy viewing later.
Version selection
The latest version 5.7.20 Community Edition
https://dev.mysql.com/downloads/mysql/
Download the compressed version:
ZIP Archive (mysql-5.7.20-win32.zip)
https://dev.mysql.com/downloads/file/?id=473308
Create configuration
As of MySQL version 5.7.18, the configuration file my-default.ini will no longer be included, so copying the configuration file will not start.
Taken from: https://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
Since then, a handwritten configuration file is performed.
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
socket=/tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M
[mysqldump]
quick
Extracted from: https://dev.mysql.com/doc/refman/5.7/en/option-files.html
Add base and data directories:
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
socket=/tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M
basedir="D:/tools/MySQL/mysql5.7.20"
datadir="D:/tools/MySQL/mysql5.7.20/data"
[mysqldump]
quick
For other configurations, you can refer to the official documentation to add them later.
See: https://dev.mysql.com/doc/refman/5.7/en/server-options.html
Detailed explanation of other bloggers: https://www.cnblogs.com/zhoujinyi/p/5614135.html
Initialize the database
Enter the directory where mysql.exe is located, such as:
Run CMD with administrator privileges
>d:
>cd "D:/tools/MySQL/mysql5.7.20/bin"
# 以下命令二选一。
# 其一,初始化数据库目录,生成随机MySQL密码至日志文件中。
# 其二,初始化数据库目录,生成(空)密码。
>mysqld --initialize
>mysqld --initialize-insecure
after execution to
Search for the keyword keyword in the ./data/DESKTOP-****.err file.
Modify ROOT password
Log in to the database using the command line.
>mysql -uroot -p -P3306
Enter password:# 输入生成的随机密码
mysql> use mysql;
mysql> desc user;
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(32) | NO | PRI | | |
| Select_priv | enum('N','Y') | NO | | N | |
......
|
| authentication_string | text | YES | | NULL | |
| password_expired | enum('N','Y') | NO | | N | |
| password_last_changed | timestamp | YES | | NULL | |
| password_lifetime | smallint(5) unsigned | YES | | NULL | |
| account_locked | enum('N','Y') | NO | | N | |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
45 rows in set (0.00 sec)
# 5.7已经取消了Password字段,取而代之的是authentication_string,而且已经"不推荐"修改表来完成实现修改用户密码。
mysql> update mysql.user set authentication_string=password('root') where user='root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
# 官方推荐使用 ALTER 方法进行修改,具体使用如下。
# 该方法不需要刷新权限表(flush privileges)即可生效。
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.00 sec)
#此次虽然提示0条影响,但实则已经修改。
mysql> select host,user,authentication_string,password_last_changed from user;
+-----------+---------------+-------------------------------------------+-----------------------+
| host | user | authentication_string | password_last_changed |
+-----------+---------------+-------------------------------------------+-----------------------+
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | 2018-01-06 21:56:39 |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | 2018-01-06 21:07:45 |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | 2018-01-06 21:07:45 |
+-----------+---------------+-------------------------------------------+-----------------------+
3 rows in set (0.00 sec)
Runs resident as a Windows service
Run CMD in administrator mode and enter the ./bin directory
Install MySQL service
# mysqld --install [服务名]
# mysqld --install-manual [服务名] 安装服务不自启
>mysqld --install MySQL57
Service successfully installed.
Uninstall MySQL service
# mysqld --remove [服务名] 存在多个版本是需要具体服务名,容易卸载错误。
>mysqld --remove MySQL57
Service successfully removed.
# 或者使用windows内置管理方式删除服务
>sc delete MySQL57
[SC] DeleteService SUCCESS
start/stop MSYQL
# 启动
net start MySQL57
#停止
net stop MySQL57
Error on startup
MySQL57 服务正在启动 .
MySQL57 服务无法启动。
服务没有报告任何错误。
请键入 NET HELPMSG 3534 以获得更多的帮助。
How to view details:
Computer Management > System Tools > Time Viewer > Windows Logs > Applications > "Specific Error Entries"
over)