MySQL5.7.20报错Access denied for user 'root'@'localhost' (using password: NO)

在centos6.8上源码安装了MySQL5.7.20,进入mysql的时候报错如下:

解决办法如下:

在mysql的配置文件内加入:

vim  /etc/my.cnf

skip-grant-tables

保存并重启mysql服务

进入mysql,修改密码:

mysql> use mysql;

mysql> update user set password=password("你的新密码") where user="root";

mysql> flush privileges;

mysql> quit

到此root账户就重置了密码,删除etc/my.cnf中,刚添加的那行内容,重启mysql就好了

如果在进行到

mysql> update user set password=password("你的新密码") where user="root";

报错:ERROR 1054 (42S22): Unknown column 'password' in 'field list'

解决措施如下:

mysql>desc user;

发现在Field列中没有password,此时我们需要这样重置密码:

mysql>update user set authentication_string=password('你的新密码') where user='root';

之后的步骤如上所示,就解决了这个问题

mysql为什么you must reset your password using alter user statement before ex

 1:  SET PASSWORD = PASSWORD(‘your new password‘);

 2:  ALTER USER ‘root‘@‘localhost‘ PASSWORD EXPIRE NEVER;

 3:  flush privileges;

完成以上三步退出再登,使用新设置的密码就行了



作者:蓝色的雪啦
链接:https://www.jianshu.com/p/0dbab1bdcaa1
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
原文地址:https://www.cnblogs.com/zhoading/p/11510403.html