Access denied for user 'root'@'localhost' (using password: YES) 数据库密码正确,没有权限

数据库密码输入正确,却没有权限登陆解决方法:

1.输入vim /etc/my.cnf (数据库配置文件),在[mysqld]下面添加 skip-grant-tables 表示允许无密码登陆,输入:wq,保存退出

2. 重启mysql

service mysql stop

service mysql start

3.输入mysql -uroot -p 回车  不用输入密码,登陆:

 4.输入 set password for 'root'@'localhost'=password('123456'); 重新设置密码

5.报的无效错误,所以不能直接修改

 

6.换种修改方式:直接修改系统user表里面的密码

use mysql;

show tables;

然后查看表结构:show columns from user;

mysql的密码存放在 authentication_string字段上面,mysql有的版本密码字段直接是password,需要仔细看。

7.更新密码: update user set authentication_string=password("root1234") where user='root';

8.刷新表 flush privileges

9.然后按照步骤一删除 配置中的 skip-grant-tables,重启mysql即可。

发布了49 篇原创文章 · 获赞 17 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/unhejing/article/details/102776166
今日推荐