进入MySQL时报ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using
password: YES)
在这里插入图片描述

解决:

1、关闭mysql service mysql stop
2、依次执行以下命令,如果/etc目录下有my.cnf文件直接修改,如果没有就拷一份,如下
cp /usr/share/mysql/my-default.cnf /etc/my.cnf

3、修改/etc/my.cnf文件
在mysqld后添加 skip-grant-tables,保存关闭后后,重启mysql服务
在这里插入图片描述
4、重启mysql服务,service mysql restart
进入mysql中 mysql -uroot
在里面执行
可以进行修改,把root改为自己的用户名,localhost改为自己的主机名
set password for ‘root’@‘localhost’ = password(‘root’);

如果在执行是报如下错误,就刷新权限在执行 flush privileges;

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

猜你喜欢

转载自blog.csdn.net/Lu_Xiao_Yue/article/details/84624443