Edit the configuration file for MySQL: My.ini (under MySQL installation directory).
Open the configuration file, add: Skip-grant-tables on the last line of the file, and then save the exit.
This means that the grant-tables does not start when you restart MySQL.
To restart the MySQL service:
net stop MySQL
net start MySQL
- 3
Set the new root password.
Mysql-u root-p Direct Enter, no need to enter the password to enter the database.
Use MySQL at the command line (switch to system database)
Execute the following statement to modify the root user password:
Update user set Password=password ("123456") where user= ' root ';
Note that the new version of the password field is changed, and the field is named "Authentication_string", so you need to execute the script below.
Update user set Authentication_string=password ("123456") where user= ' root ';
- 4
Restore the configuration file and delete the row you just added in the configuration file. Then restart the MySQL service and you will be able to log in with the newly set password.
Add a password to the root user after MySQL installation is complete