Access denied for user 'root'@'localhost' (using password: YES) appears when logging in to MySQL8.0 (perfect solution)

Today, when I opened mysql normally, I suddenly got the prompt: Access denied for user 'root'@'localhost' (using password: YES)

I searched a lot of articles on the Internet, tried their solutions, and found that none of them worked. Finally, I tried combining the key points of multiple methods to find a perfect solution.

The first step: Stop the Mysql service first. This step is very important .

Step 2: Find the my.ini file in the Mysql installation path, right-click to edit, and enter under mysqld to skip password detection.

skip-grant-tables

 Save and exit the file, remember to save.

Step 3: Run cmd as administrator, which is also commonly known as: black window. Must be run as administrator

Step 4: Enter the command line mysqld --console --skip-grant-tables --shared-memory in cmd

 Step 5: Open cmd as administrator again. Second black window. Enter mysql directly to enter MySQL.

Step 6: Execute the command: update user set authentication_string ='' where user = 'root'; Clear the password. Because MySql8+ is a little different from previous versions, the user table does not have a password field, but an authentication_string.

Step 7: Enter the command: flush privileges; to make the changes take effect. exit exit mysql.

Step 8: Close both black windows and re-run the two black windows: Repeat steps 3 to 5 again .

Step 9: Use the command in the mysql window: ALTER user 'root'@'localhost' IDENTIFIED BY '123'; Set the password to 123. It's OK.

Finally, just comment out skip-grant-tables in the my.ini file with #, restart the mysql service, and you can enter.

Guess you like

Origin blog.csdn.net/Flocexxxx/article/details/130755216