[问题解决] Mysql8.0.13 登录报1045(28000)错误

荒凉一梦 提交于 2020-01-06 22:04:57

【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>

以下修改登录密码报错:
mysql-8.0.13 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

一、修改root密码

mysql> update mysql.user set authentication_string="123456" where user="root";

或:mysql>update mysql.user set authentication_string="123456" where user="root" and host='localhost';

#刷新权限(必须步骤)

mysql> flush privileges;

#查询密码是否生效:

mysql> select host,user,authentication_string from mysql.user;

mysql-8.0.13修改密码后mysql>quit  再次登录。

>mysql - u root -p

password:123456 

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

找到一种解决方法:

1、cmd-1窗口:无密码启动mysql服务

mysqld --console --skip-grant-tables --shared-memory;

#--skip-grant-tables 的意思是启动MySQL服务的时候跳过权限表认证。

#无密码启动mysql服务

2、无密码登录,再次修改密码。

再开一个CMD窗口(前一个CMD窗口已经不能动了),转到mysql\bin目录

>mysql -u root -p

->密码不输入直接enter

无密码登录mysql服务

#修改密码为空

mysql>UPDATE mysql.user SET authentication_string='' WHERE user='root';

mysql>flush privileges;    

myslq>quit   

#再次登录无密码登录

>mysql - u root -p

Enter password: 

#enter不输入密码进入mysql

------------------------------------------------------------------------------------

查询网上资料,可能是MySQL8.0的caching_sha2_password问题,再来试试

MySQL8.0采用了新的更安全的验证方式,原有修改密码方法修改密码后无法登录

mysql>update mysql.user set authentication_string="123456" where user="root" and host='localhost';

正确修改root密码:
1、首先查询用户

mysql> select host,user,plugin,authentication_string from mysql.user;

2、修改密码和密码方式

mysql>ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

mysql> flush privileges;

3、退出再次登录,成功。

或者也可以修改密码后再修改plugin

1、mysql>update mysql.user set authentication_string="123456" where user="root" and host='localhost';

2、mysql> UPDATE mysql.user SET plugin='mysql_native_password' WHERE user='root';

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!