ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) (MySQL resets the password)

Problem Description:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Screenshot of the problem:

insert image description here

problem causes:

solution:

Reference address: https://blog.csdn.net/m0_46278037/article/details/113923726

1. Close the MySQL service

net stop mysql

2. Skip password verification

Open cmd with an administrator, enter the bin folder in the mysql directory, and use mysqld -console --skip-grant-tables --shared-memoryto skip permission verification ( the difference between mysql8.0 and other versions is that you cannot directly use mysqld --skip-grant-tables to skip password login ).
insert image description here

3. Enter Mysql without password

Use the administrator to open a new cmd window, enter the bin folder in the mysql directory, and enter it directly mysql -u root -p. When prompted to enter a password, just press Enter to skip it.

4. Set the login password to empty

Enter the code and set the password to empty (the password cannot be changed directly at this time, it must be set to empty first, otherwise an error will be reported).

use mysql; (使用mysql数据表)
update user set authentication_string='' where user='root';(将密码置为空)
quit; (然后退出Mysql)

insert image description here

5. Change your login password

Close other cmd windows, leaving only the last one open.

net stop mysql(关闭mysql服务,虽然会显示没有开启服务,但是以防万一)
net start mysql(再打开mysql服务)
mysql -u root -p (此处会显示输入密码,直接回车就好了,第四步我们已经将他置为空了)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';(更改密码)

insert image description here

6. Verify whether the modification is successful

quit(退出mysql)
mysql -u root -p (输入新密码,再次登录)

insert image description here

Guess you like

Origin blog.csdn.net/qq_37515374/article/details/129649926