Description of the version
- The reason why it is said to be MySQL 5.7 and above is that its security mechanism has changed since MySQL 5.7. After the installation is complete, when logging in to MySQL, you need to enter a password. This password is actually a random password generated during the configuration of MySQL, and we must find this random password to log in to MySQL. Versions before 5.7 do not need to do this, so for versions before 5.7, this tutorial may not be fully applicable, but there are many online, if you need to search for it yourself.
system environment
- win10, 64 bit
MySQL version
- 5.7.20 Free installation version
MySQL download address
- https://dev.mysql.com/downloads/mysql
- Pull down on the download page, select your operating system version and bit number, and then download it.
MySQL installation
- Since the MySQL selected here is an installation-free version, decompression is installation, and you can decompress MySQL to the location you want to put it.
Environment configuration
Add the path of the bin directory after MySQL decompression in the environment variable Path. For example, mine is: D:\mysql-5.7.20-winx64\bin. If you don’t know where the environment variable Path is, you can click here
Run cmd as an administrator (put the mouse on the windows icon in the lower left corner of the screen, click the right mouse button, select Command Prompt (Admin) (A)), enter D:, then press Enter, enter the D drive ( The disk where MySQL is decompressed)
Continue to enter the bin directory in MySQL and enter the following command:
cd mysql-5.7.20-winx64\bin
- 1
Notice:
- The path and name here should be the same as those on your own computer. Here I only use my own as an example. The same below
To install mySQL, enter the following command
mysqld -install
- 1
Then enter:
mysqld --initialize
- 1
Then press Enter (it may take a while), then a data folder will be generated in the root directory of MySQL, pay attention to a file that ends with .err, and the initial password is in this file (you can press Ctrl+F Search for password to find the password), this initial password will be used later
Configure the MySQL startup file
If there is a file named my-default.ini in the unzipped MySQL, enter the following items in the configuration file:
basedir=D:\mysql-5.7.20-winx64 datadir=D:\mysql-5.7.20-winx64\data port=3306
- 1
- 2
- 3
Notice:
- The path and name here still need to be the same as those on your computer
If there is no file named my-default.ini in the decompressed MySQL, create a new file named my.ini in the root directory, then select the file, click the right mouse button, and choose to open with Notepad. where enter:
[mysqld] basedir=D:\mysql-5.7.20-winx64 datadir=D:\mysql-5.7.20-winx64\data port=3306
- 1
- 2
- 3
- 4
After the input is complete, click Save and close.
Start the MySQL service: enter the MySQL bin directory (after the previous steps, it is now in the MySQL bin directory), enter
net start mysql
- 1
Log in to MySQL and enter the following command:
mysql -u root -p
- 1
As can be seen from the above figure, we are required to enter a password here. This password is the initial password automatically generated by MySQL, which has been mentioned in step 5 above. Find the file ending with .err, choose to open it with Notepad, and then search for password in the file, you can see the following search results, the part outlined by the red line is the initial password (the password generated by each user is different, put You can find your own)
Copy this initial password, and then enter it in cmd. If you see the interface shown in the figure below, it means that MySQL has been successfully configured .
Change the initial password
For the convenience of remembering the password and for security reasons, we can reset the MySQL login password. After successfully completing step 8, we then enter
set password for root@localhost=password('xxxxxx');
- 1
Notice:
- The xxxxxx in single quotes represents the password you set, you can change it yourself
- The semicolon after the statement also needs to be entered. If you do not enter it for the first time, you can also enter the semicolon after the carriage return.
If the password is set successfully, the following interface will appear:
Exit MySQL: then enter
quit
- 1
Log in with the new password (must be in the MySQL bin directory), enter
mysql -u root -p
- 1
Then enter the new password you just set, press Enter, and the login is successful.
So far, MySQL has been successfully configured, and the initial password has been modified, and you can use it to your heart's content!