After many trials, the steps to reset the password are as follows
step1. Open the command window cmd, enter the command: net stop mysql, stop the MySQL service,
step2. Turn on the MySQL service that skips password authentication login
input the command
mysqld --console --skip-grant-tables --shared-memory
step3. Open a new cmd, log in to MySQL without a password, and enter the login command: mysql -u root -p
step4. Leave the password blank, the command is as follows:
use mysql
update user set authentication_string='' where user='root';
step5. Exit mysql and execute the command:
quit
step6. Shut down the MySQL service started with -console --skip-grant-tables --shared-memory
,
step7. Open the command box and enter: net start mysql
to start the MySQL service.
step8. The password in step 4 has been left blank, so log in to MySQL without a password, and enter the login command: mysql -u root -p
step9. Use the password change command in the previous blog to successfully change the password, as shown below:
ALTER USER 'root'@'localhost'
IDENTIFIED BY 'newpasswd';
step10. After verifying that the password is correct, log in
Enter quit, exit the current login, enter the login command: mysql -u root -p
Enter the password and log in successfully. This is the end of resetting the password.