Configure MySQL 5.7 and mysql Database Service on Windows
Including the process of initializing the root user password and two Common Problems
1. Download the MySQL zip package
Go to [MySQL official website] (http://dev.mysql.com/downloads/mysql) Select zip package download and unzip as needed,
For example, I downloaded a mysql-5.7.17-winx64 from my computer.
Http://dev.mysql.com/downloads/mysql/
2. Edit the MySQL configuration file
Open the decompressed mysql.zip package, find the my-defalult.ini in it, the file is the default configuration file of MySQL
We recommend that you copy the file and rename it my. ini.
Edit my. ini. Here I only configure the port, MySQL installation directory, and MySQL database storage directory.
> [Mysqld]> # Set port 3306> port = 3306> # Set MySQL installation directory> basedir = C: \ mysql-5.7.17-winx64 \ mysql-5.7.17-winx64> # Set the directory for storing MySQL database data> datadir = C: \ mysql-5.7.17-winx64 \ mysql-5.7.17-winx64 \ data
3. install and configure the MySQL Service
Use admin permission to open the CMD run window and go to the MySQL bin directory to execute the following install command
C:\mysql-5.7.17-winx64\mysql-5.7.17-winx64\bin>mysqld -installService successfully installed.
Run the net start mysql command to open the MySQL service.
net start mysql
PS: Question 1
Description: An error occurred while starting the MySQL service.
C:\mysql-5.7.17-winx64\mysql-5.7.17-winx64\bin>net start mysqlThe MySQL service is starting.The MySQL service could not be started.The service did not report an error.More help is available by typing NET HELPMSG 3534.
Solution:
Some searches on the network show that the bin \ data DIRECTORY needs to be initialized before MySQL service is started after version 5.7,
My approach is:
-Create the bin \ data directory. If the previous directory is deleted, run the initialization command in the "run admin" window to generate the root user without a password: C: \ mysql-5.7.17-winx64 \ mysql-5.7.17-winx64 \ bin> mysqld -- initialize-insecure-try to open the MySQL service again, no accident will return success: C: \ mysql-5.7.17-winx64 \ mysql-5.7.17-winx64 \ bin> net start mysql The MySQL service is starting. the MySQL service was started successfully.
Check that the MySQL service is enabled.
Run the net start command to list all the windows services that have been opened. If MySQL is found in the output, the operation is successful:
C:\mysql-5.7.17-winx64\mysql-5.7.17-winx64\bin>net startThese Windows services are started: ... MySQL ...
4. initialize the root user password
Go to MySQL
Because the generated root does not contain a password, you can run the following command to access MySQL without a password:
mysql -u root
Select MySQL database
mysql> use mysql;
You can use SQL statements to view the user table data and check whether the root account has a password.
mysql> select user, authentication_string from user;+-----------+-------------------------------------------+| user | authentication_string |+-----------+-------------------------------------------+| root | || mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |+-----------+-------------------------------------------+2 rows in set (0.00 sec)
Initialize password for the MySQL root User
Mysql> update user set authentication_string = password ('Password') where user = 'root'; Query OK, 1 row affected, 1 warning (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 1
PS: Question 2
Description: failed to use the following command to initialize the password.
Mysql> update user set password = PASSWORD ('Password') where user = 'root ';
Solution:
You can view the user table information and find that the password field has been removed from the user table of the new MySQL version,
Replace it with authentication_string. Therefore, if you use this command, an error is returned.
Confirm the root user information in the user table again, and you can see that the root user already has the password.
mysql> select user, authentication_string from user;+-----------+-------------------------------------------+| user | authentication_string |+-----------+-------------------------------------------+| root | *8B62E5775164CCBD6B3F9FFFC5ABCEFGHIGKLMNO || mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |+-----------+-------------------------------------------+2 rows in set (0.00 sec)
Run the flush privileges command to make the change take effect.
mysql> flush privileges;Query OK, 0 rows affected (0.01 sec)
Exit MySQL
mysql> exitBye
Log on to MySQL with the root password
C:\mysql-5.7.17-winx64\mysql-5.7.17-winx64\bin>mysql -u root -pEnter password: *********Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 5Server version: 5.7.17 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
The above section describes how to configure MySQL Database Service with version 5.7 on the Windows platform. I hope it will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!