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

时间:2021-07-01 19:19:29

解决方案:
1. vim /etc/my.cnf
在文件的最后添加一行“skip-grant-tables”,保存并关闭文件(设置跳过密码验证)

2.systemctl restart mysqld.service(重启数据库)

3.mysql -uroot -p,要求输入密码时直接回车

4.set global read_only = 0;
flush privileges;

5.grant all privileges on . to ‘root’@’localhost’ identified by ‘root’ with grant option;

6.重启数据库,OK