MySQL 5.7 root用户不能登录的问题
前篇文章介绍了CentOS中安装了MySQL 5.7root密码找回的问题,许多人使用银众云主机的用户反应在配置环境时第一次能使用root用户登录,但后面root用户就一直无法登录了,提示ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES),这段话的意思是,拒绝访问用户的根'@'本地主机'(使用密码:是的),是指采用密码登录而不是提示密码正确,因为你随便输入一个密码也是会这样提示的。
网上有过很多类似问题的教程,但都无法解决此问题,真正的解决方式是:
1,停止mysql 服务: service mysqld stop
2,跳过授权登录:mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
3,勿密码登录: mysql -u root
4,查看用户的权限:select * from mysql.user\G;
结果发现:
Grant显示N--mysql权限架构体系(应该是这么说)是关闭的,so.............
5,授权 grant all on *.* to 'root'@'localhost' identified by '123456' with grant option; 注:123456是密码
6,刷新flush privileges;
7,如果提示ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
执行 alter user 'root'@'localhost' identified by 'er27cSU4x8?';
OK