问题描述
数据库连接失败
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
Client does not support authentication protocol requested by server; consider upgrading MySQL client
问题原因
mysql8 以前的版本加密规则是mysql_native_password,而mysql8之后,加密规则是caching_sha2_password。
在数据库连接的时候加密规则出现不适配。navicat登录数据库,连接时也可能会出现同样的问题。
解决方法
把用户密码登录的加密规则还原成mysql_native_password这种加密方式
use mysql;
alter user 'root'@'localhost' identified with mysql_native_password by 'password';//password是你自己的密码
flush privileges;#刷新权限,使自己的修改生效
这个修改的是localhost,对于非本机的连接密码校验规则还是没有变。
select user,host,plugin from user where user='root';
select user,host from user;
如果host是%,只需把localhost要改成对应的%即可。