问题场景描述:
javaweb项目启动,进行用户登录验证,连接mysql,查询数据时报该错误
Client does not support authentication protocol requested by server; consider upgrading MySQL client
初步判断
先查看 mysql的版本
mysql> select version(); +-----------+ | version() | +-----------+ | 8.0.28 | +-----------+ 1 row in set (0.00 sec)
一般8版本的mysql,会在加密规则那块出现问题,再看mysql8的加密规则
mysql> use mysql; Database changed mysql> select user,host,plugin from user where user='root'; +------+-----------+-----------------------+ | user | host | plugin | +------+-----------+-----------------------+ | root | localhost | caching_sha2_password | +------+-----------+-----------------------+ 1 row in set (0.00 sec)
发现加密规则确实需要调整,出现这个问题的原因是:
安装mysql8的时候,没有去修改加密规则,导致后面查询数据库的时候,会报这个错误
抽丝剥茧
通过修改登录密码的方式修改加密规则:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123'; #修改密码 FLUSH PRIVILEGES; #刷新权限
记住,此时,登录密码,我们已经改成了 123
我们再看一下加密规则:
mysql> use mysql; Database changed mysql> select user,host,plugin from user where user='root'; +------+-----------+-----------------------+ | user | host | plugin | +------+-----------+-----------------------+ | root | localhost | mysql_native_password | +------+-----------+-----------------------+ 1 row in set (0.00 sec)
加密规则变成了 mysql_native_password ,这样就ok了。
总结
1、出现问题,先查看mysql版本
2、如果是mysql8版本,那么看一下加密规则,如果加密规则是caching_sha2_password ,则需要修改
3、修改加密规则
(1)ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘123’;
(2)FLUSH PRIVILEGES