700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 如何解决MySQL 5.7 Access denied for user 'root'@'localhost' (using password YES)问题?

如何解决MySQL 5.7 Access denied for user 'root'@'localhost' (using password YES)问题?

时间:2020-01-16 10:50:16

相关推荐

如何解决MySQL 5.7 Access denied for user 'root'@'localhost' (using password YES)问题?

欢迎转载,转载请注明出处,谢谢~(作者:喝酒不骑马 Colton_Null)

from CSDN

最近,在CentOS 6.8上使用MySQL时,无法登录数据库,并提示Access denied for user ‘root’@’localhost’ (using password:YES)

经过查阅大量资料,现总结一下可用的解决方法

1.首先关闭MySQL服务

[root@localhost /]# service mysqld stop

2.安全启动MySQL(跳过密码验证)

[root@localhost /]# /usr/bin/mysqld_safe --skip-grant-tables

这时候会报

mysqld_safe Logging to '/var/lib/mysql/iZ23dq2wm0jZ.err'.mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

我用SecureCRT连接的Linux,到这时候就卡住了,ctrl + c也不能退出。后来找到解决方法:卡住时,在用SecureCRT开启一个新的连接到系统上继续操作就可以了。

3.登录MySQL

[root@localhost /]# mysql -u root

4.更改密码

mysql> grant all privileges on *.* to 'root'@'localhost' identified by '123465' with grant option;

其中’root’@’localhost’ 是用户名

第二个’123465’是新密码

如果此处报错The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

则说明没有写入权限,这时候就要关闭数据库只读属性

mysql> set global read_only=0;// 关掉数据库的只读属性mysql>flush privileges;// 刷新配置

之后,再执行修改密码操作

最后,可以再将属性设置回初始状态

mysql> set global read_only=1;// 关掉数据库的只读属性mysql>flush privileges;// 刷新配置

5.重启数据库

[root@localhost /]# service mysqld restart

这时候,就可以用刚才设置的新密码123465登录数据库了。问题解决。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。