Linux运行MySQL5.7报错ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

问题:密码错误,解决办法:重置密码。

Linux运行MySQL5.7报错ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

步骤:

1、关闭MySQL服务:service mysql stop。(若mysql服务在开启状态:用ps -ef|grep mysql检查)

2、修改MySQL配置文件my.cnf,一般my.cnf文件在/etc目录下。

Linux运行MySQL5.7报错ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

3、在配置文件的[mysqld]标签下添加:skip-grant-tables;保存后退出,并启动MySQL服务:service mysql start

Linux运行MySQL5.7报错ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

4、启动进入MySQL,此时要求输入密码,直接回车就跳过进入MySQL了。

Linux运行MySQL5.7报错ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

或者:输入mysql命令进入。

Linux运行MySQL5.7报错ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

5、修改MySQL密码:update mysql.user set authentication_string=password('新密码') where user='用户';

执行:flush privileges;

退出MySQL。


6、再次编辑 /etc/my.cnf,删除 skip-grant-tables 保存退出

7、重启MySQL服务:service mysql restart;进入MySQL

Linux运行MySQL5.7报错ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

到此设置完成!