欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

解决连接mysql报错:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

程序员文章站 2022-05-01 14:46:11
...

解决ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

问题:(我的Windows下mysql版本号:5.7.31)

忘记密码或其他一些原因导致无法连接上MySQL服务器端,在命令行报错:

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

解决方案:

步骤一:先在安装目录下找到my.ini配置文件,打开配置文件,找到[mysqld]一行,在下面添加skip-grant-tables后保存该文件。

如果你安装完mysql之后或者是下载的免安装版解压之后,默认是没有my.ini文件的。你可以通过下面链接知道如果配置出一个my.ini文件。
https://blog.csdn.net/weixin_42365757/article/details/108316556

配置完成之后重新启动mysql服务

步骤二:重新启动数据库服务端mysq程序:

快捷键 windows + R => 输入services.msc=>找到MySQL 右键重启动此服务(前提是你之前已经把MySQL加入了系统服务中):
解决连接mysql报错:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

步骤三:然后在cmd中执行: mysql -u root mysql

解决连接mysql报错:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

步骤四:更改你的mysql密码

mysql>update user set password=password('root') where user='root';
mysql>Flush privileges;

其中root为root的新密码。

注意:如果你发现你执行update user set password=password(‘root’) where user=‘root’;报错:
ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’,你可以通过下面步骤或链接知道如果更改MySQL5.7的密码:

https://blog.csdn.net/weixin_42365757/article/details/108316291[更改mysql密码的具体步骤,超详细]。

问题所在一般都是mysql数据库下已经没有password这个字段了,password字段改成了authentication_string 所以更改语句替换为
update mysql.user set authentication_string=password('root') where user='root' ;
即可更改密码。

步骤四:将刚才my.ini配置文件的新增的那一行去掉(skip-grant-tables),最后重新启动mysql服务就可以了。

解决连接mysql报错:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

相关标签: mysql常见问题