如何解决 MySQL报错:ERROR 1045 (28000)

如何解决 MySQL报错:ERROR 1045 (28000)

一、问题复现

┌──(rabbit㉿ASUS)-[/mnt/c/Users/rabbit]
└─$ mysql -uroot -p3xxxxxxxS9uccj -h192.168.xxx.xxx
ERROR 1045 (28000): Access denied for user 'root'@'ASUS.lan' (using password: YES)

二、问题解决

mysql> select user, plugin from mysql.user;
+------------------+-----------------------+
| user             | plugin                |
+------------------+-----------------------+
| root             | auth_socket           |
| debian-sys-maint | caching_sha2_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session    | caching_sha2_password |
| mysql.sys        | caching_sha2_password |
+------------------+-----------------------+
5 rows in set (0.00 sec)

mysql> update mysql.user set plugin='mysql_native_password' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
// 修改用户插件模式,这是报错的根源所在。

mysql> alter user 'root'@'%' identified by '3n6wxxxxxccj';
// 由于 mysql 不断更新,重设密码方式一直变化。
// 该方法是通用方法,故说明。

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
// 记住需要刷新特权表,否则不生效。

mysql> 
posted @ 2021-10-18 15:28  季文康  阅读(478)  评论(0编辑  收藏  举报