侧边栏壁纸
博主头像
勤奋的冬枣博主等级

只有把抱怨环境的情绪,化为上进的力量,才是成功的保证!

  • 累计撰写 273 篇文章
  • 累计创建 448 个标签
  • 累计收到 116 条评论
标签搜索

目 录CONTENT

文章目录

MySQL5.7报错Access denied for user 'root'@'localhost'

勤奋的冬枣
2019-12-01 / 0 评论 / 0 点赞 / 520 阅读 / 0 字

MySQL5.7报错Access denied for user 'root'@'localhost' 的后面还有个(using password: YES),这个说明密码是对的,但是就是不能登陆!

1.jpg

错误信息

但是,我们检查的时候发现MySQL本身的状态都是正常的!

2.jpg

运行状态

解决办法如下:

1、在mysql的配置文件内加入:

vim /etc/my.cnf           #打开配置文件

加入下面内容:

skip-grant-tables #在登录时不需要密码

保存并重启mysql服务

service mysqld stop          #停止MySQL

Redirecting to /bin/systemctl stop mysqld.service

service mysqld start         #开启MySQL
Redirecting to /bin/systemctl start mysqld.service

也可以直接使用:

service mysqld restart           #重启MySQL

2. 进入mysql,修改密码:

3.jpg

回车直接进入

mysql> use mysql;              #进入MySQL账户
mysql> update user set password=password("你的新密码") where user="root";         #配置新的密码
mysql> flush privileges;            #刷新
mysql> quit                         #退出

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

3.再次将配置文件中的“skip-grant-tables”删除,然后重新启动!

但是:如果在进行到

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

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

4.jpg

报错 解决措施如下:

mysql>desc user;

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

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

5.jpg

解决方法

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

0

评论区