前言
Mysql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES/NO)
看了很多篇文章都没解决, 下面是我个人解决方法 分享一下
一、个人配置:系统win10,MySQL : 8.0.30 数据库工具:Navicat
二、原因 root用户的密码错误
1.ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)

Access denied(拒绝访问)
using password:NO (没有就输出NO)
2.ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

Access denied(拒绝访问)
using password:YES (输入了就表示YES)
三、解决方法
1.停止mysql的服务
CTRL+ALT+DELETE 打开任务管理器,切换到“服务” 选中右键点击停止


确认mysql服务停止,不然data文件占用删不掉

2.删除mysql目录下的 data 文件夹

3.bin目录下 点击地址栏 输入CMD 敲下回车

输入CMD 敲下回车


输入 mysqld --initialize 生成 data 文件夹

4. 在重新生成的data文件夹下,找到.err文件

这个文件里有重新生成的 root@localhost 的密码

拿到密码后,把mysql服务启动


确认启动后,进行下一步

回到CMD后,输入 mysql -u root -p 后,敲回车,复制上图的密码

最后回到Navicat

把上面的密码复制到这里的密码栏后,点确定

打开连接后 ,会提示密码过期,重新输入密码,这时就填上个人密码就可以了


修改完成后

最后感谢 两位的文章
li.siyuan 参考链接
我是夜阑的狗 参考链接