mysql: this authentication plugin is not supported
错误原因
mysql 在 8.0 之后将用户使用的 plugin 更新成 caching_sha2_password。而在之前用的是 mysql_native_password
查看 plugin
1
2
  | 
use mysql;
select user,host,plugin from user;
  | 
 
可以看到
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
  | 
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| root             | %         | mysql_native_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
| abc              | localhost | mysql_native_password |
+------------------+-----------+-----------------------+
5 rows in set (0.00 sec)
  | 
 
上面的 root, abc 用户是我修改后的 plugin, 修改前的是 caching_sha2_password
解决办法
- 降级 mysql
 
- 修改 plugin 为 mysql_native_password
 
修改 plugin
使用命令
1
  | 
ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘密码’;
  | 
 
修改密码的同时,并指定编码为 mysql_native_password.
使用这个命令之后, 再次查看的结果就会是上面表格的 plugin 了.
this user requires mysql native password authentication
但是,当你在程序中这样连接时:
1
  | 
abc:abc@(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local
  | 
 
你会发现, 还是不能用~ 报this user requires mysql native password authentication错 气不气..
解决办法
将上面的连接字符后添加一个参数就可以解决这个问题 allowNativePasswords=true.
最后的连接字符串为
1
2
  | 
abc:abc@(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local
&allowNativePasswords=true
  | 
 
再次启动程序就可以了.