jsp连接mysql出现不支持认证协议的解决办法

时间:2022-05-30 00:28:42

错误提示

com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client

 

错误原因

Mysql8 之前的版本中加密规则是mysql_native_password,而在Mysql8之后,加密规则是caching_sha2_password

笔者在jsp中使用的Mysql的架包是mysql-connector-java-5.0.8-bin.jar,如果使用的MySql8以上就会报错

 

解决办法

更换加密算法

mysql> select version();
 ----------- 
| version() |
 ----------- 
| 8.0.17    |
 ----------- 
1 row in set (0.01 sec)

mysql> ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY 123;
Query OK, 0 rows affected (0.02 sec)

mysql> FLUSH PRIVILEGES; 
Query OK, 0 rows affected (0.01 sec)