Centos7 mysql出现Access denied for user ‘root‘@‘localhost‘

141 阅读1分钟

解决如下:

1.停止mysql服务

systemctl stop mysqld.service

2.修改配置文件无密码登录

vim /etc/my.cnf

在最后加上

skip-grant-tables

保存

3.启动mysql

systemctl start mysqld.service

4.登录mysql

mysql -u root

注意这里不要加-p

5.修改密码,mysql5.7用此语法

use mysql;

update mysql.user set authentication_string=password('123456') where user='root' ; flush privileges;

6.回到第二部把刚加的那句删掉

保存,重启mysql就可以了