【mysql】修改密码(ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES))

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

登录一直密码错误

可能原因

同一个用户不同host密码不同导致的

解决方式

  • 登录不进去的情况下在/etc/my.cnf文件中[mysqld]下添加skip-grant-tables

  • 重启mysql服务

service mysql restart

  • 查询host,user,authentication_string
select host,user,authentication_string from user where user='root';

从图中可以看出同一个用户本地和%的authentication_string不同

说明使用root用户在本机使用的密码和在其他地方用的密码不同

%代表所有host

但是单独设置了localhost就和其他的密码不同了(同一用户下)

再设置其他host的密码同样和%(其他)的密码不同了(同一用户下)

找到问题所在,修改密码

修改本机的密码

set password for 'root'@'localhost' = password('123456');

修改所有host的密码

set password for 'root'@'%' = password('123456');

示例密码过于简单,请勿模仿

如果执行以上的设置密码命令出现错误ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

先执行一下  flush privileges;

如果在其他地方能登该该用户的的mysql,就是%的密码,例如在window可视化数据库连接工具navicate可以登录,那么也可以直接把mysql中user数据库user表的user=‘root’,host为localhost的那条记录删掉,只留user=‘root’,host=‘%’的记录

delete from user where user='root' and host='localhost';

猜你喜欢

转载自blog.csdn.net/qq_44065303/article/details/112477547