mysql无法登陆,报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) ,登陆不上

发布时间 2023-11-22 10:39:49作者: mrdongdong

问题描述

在使用命令行登录 MySQL 时出现了下述问题:

 

出错原因

  • using password: NO:表示输入没有输入密码就尝试登陆了
  • using password: YES:表示输入了密码,但密码错误

 

解决方案:修改密码

1.修改mysql配置文件my.cnf 。 在 [mysqld] 增加 skip-grant-tables  无密码进入mysql

 

这样我们就可以通过无密码 或乱输一个 进入到mysql。  通过select user,host from mysql.user;   查看 明明有权限 但登录不了。 直接重置密码就好了

2.密码设置为空 依次输入:  use mysql;   update user set authentication_string='' where user='root';  quit

3.编辑配置文件 注销掉第一步增加的配置 skip-grant-tables     重启mysql

 

4.无密码登录后 ,修改mysql密码

set password for 'root'@'localhost' = '123'; 

set password for 'root'@'%' = '123'; 

 

5.随后就可以正常登录了