ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)(MySQL重置密码)

问题描述:

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

问题截图:

在这里插入图片描述

问题原因:

解决方案:

参考地址:https://blog.csdn.net/m0_46278037/article/details/113923726

1、关闭MySQL服务

net stop mysql

2、跳过密码验证

用管理员打开cmd,进入mysql目录中bin文件夹下,使用mysqld -console --skip-grant-tables --shared-memory来跳过权限验证(mysql8.0与其他版本不同的地方在于无法直接使用mysqld --skip-grant-tables来跳过密码登录)。
在这里插入图片描述

3、无密码方式进入Mysql

用管理员新打开一个cmd窗口,进入mysql目录中bin文件夹下,直接输入mysql -u root -p,提示需要输入密码时直接回车即可跳过。

4、将登陆密码设置为空

输入代码,将密码设置为空(此时还不能直接修改密码,必须先设置为空,否则会报错)。

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

在这里插入图片描述

5、更改自己的登陆密码

关闭其它cmd窗口,只保留最后一个开启的。

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

在这里插入图片描述

6、验证是否修改成功

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

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_37515374/article/details/129649926