Windows Platform Configuration Version 5.7 + MySQL Database Service

  • 2021-08-21 21:41:51
  • OfStack

Includes the process of initializing the root user password password and solutions to two common problems

1. Download the MySQL zip package

Enter [MySQL official website] (http://dev.mysql.com/downloads/mysql), select zip package to download and decompress as needed,

For example, now I download mysql-5. 7.17-winx64 from my computer

http://dev.mysql.com/downloads/mysql/

2. Edit the MySQL configuration file

Open the extracted mySQL. zip package and find my-defalult. ini, which is the default configuration file for MySQL

It is recommended to copy one copy here and change its name to my. ini

Edit my. ini, where I only configured the port, the MySQL installation directory and the MySQL database storage directory


 > [mysqld]
  > #  Settings 3306 Port 
  > port = 3306
  > #  Settings MySQL Installation directory of 
  > basedir=C:\mysql-5.7.17-winx64\mysql-5.7.17-winx64
  > #  Settings MySQL The storage directory of the data in the database 
  > datadir=C:\mysql-5.7.17-winx64\mysql-5.7.17-winx64\data

3. Install and configure the MySQL service

Open the CMD running window with admin permission, enter the bin directory of MySQL and execute the following install command


C:\mysql-5.7.17-winx64\mysql-5.7.17-winx64\bin>mysqld -install
Service successfully installed.

Run the net start mysql command to open the MySQL service


net start mysql

PS: Question 1

Description: Failed to start MySQL service


C:\mysql-5.7.17-winx64\mysql-5.7.17-winx64\bin>net start mysql
The 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:

According to the search on 1 network, after version 5.7, before starting MySQL service, you need to initialize bin\ data directory.

My approach is:


-  Create bin\data Directory, if there is, delete the previous 
  -  In just admin Permissions to execute initialization commands to generate a root Users: 
    C:\mysql-5.7.17-winx64\mysql-5.7.17-winx64\bin>mysqld --initialize-insecure
  -  Try to open it again MySQL Service, 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 open

Run the net start command to list all windows services that have been opened, and find MySQL in the output for success:


C:\mysql-5.7.17-winx64\mysql-5.7.17-winx64\bin>net start
These Windows services are started:
    ...
  MySQL
    ...

4. Initialize the root user password

Enter MySQL

Since the root we just generated does not come with a password, you can access the MySQL without a password by using the following command


mysql -u root

Choose to use MySQL database


mysql> use mysql;

Viewing the user table data through the sql statement can confirm that there is no password in root at present


mysql> select user, authentication_string from user ; 
+-----------+-------------------------------------------+
| user   | authentication_string           |
+-----------+-------------------------------------------+
| root   |                      |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+-----------+-------------------------------------------+
2 rows in set (0.00 sec)

Initialize password for 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: Password initialization failed with the following command


C:\mysql-5.7.17-winx64\mysql-5.7.17-winx64\bin>mysqld -install
Service successfully installed.
0

Solution:

You can see by looking at the user table information that the password field has been removed from the user table in the new version of MySQL,

Instead, it is replaced with authentication_string, so using this command will return an error.

Confirm the root user information under the user table again, and you can see that the root user now has the password.


C:\mysql-5.7.17-winx64\mysql-5.7.17-winx64\bin>mysqld -install
Service successfully installed.
1

Execute the flush privileges command to take effect


C:\mysql-5.7.17-winx64\mysql-5.7.17-winx64\bin>mysqld -install
Service successfully installed.
2

Exit MySQL


mysql> exit
Bye

Login to MySQL with root password


C:\mysql-5.7.17-winx64\mysql-5.7.17-winx64\bin>mysqld -install
Service successfully installed.
4

Related articles: