Linux下报错MySQL Access denied for user ‘root‘@‘localhost‘ (using password: YES)解决方案

1.先进入root模式

2.进入#vim /etc/my.cnf
在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程,保存退出

3.systemctl restart mysql#重启服务   或者    service mysqld restart#重启服务

4.mysql -uroot -p 没有密码可以直接进入

5.update mysql.user set authentication_string=PASSWORD('你的新密码') where USER='root';

6.flush privileges;#刷新权限表

7.再次vim /etc/my.cnf 删除添加的skip-grant-tables保存退出

8.mysql -uroot -p'你设置的新密码'进入到MySQL中需要再次重新设置密码

 set global validate_password_policy=0;set global validate_password_length=4;//可以修改MySQL密码策略使密码更简单

9.set password=password("新密码");//可以和上面的密码重复

10.接下去就可以使用了 

进入MySQL

use mysql

查询user

mysql> select user, host from user;

修改userHost表内容修改为%

mysql> update user set host="%" where user="root";

猜你喜欢

转载自blog.csdn.net/weixin_59055372/article/details/132047228