连接MySQL 8.0时报错caching_sha2_password解决方案

bash 复制代码
java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'.
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:868)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:864)
	at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1746)
	at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)
	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2191)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2222)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2017)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
	at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:156)
	at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:218)
	at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1572)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1636)
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2505)
Sun Aug 27 15:43:26 CST 2023 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

由于我安装的mysql 8.0,8.0和5.x其中一个改动就是加密认证方式发生改变:

  • caching_sha2_password是8.0
  • mysql_native_password是5.x

解决方案

更改mysql的jdbc版本

直接在xx.pom修改版本号即可。

mysql jdbc的maven链接:http://mvnrepository.com/artifact/mysql/mysql-connector-java

比如:

xml 复制代码
<mysql-connector.version>8.0.33</mysql-connector.version>
相关推荐
运维行者_2 分钟前
APM 性能监控是什么?从应用监控与网站监控了解基础概念
网络·数据库·云原生·容器·kubernetes·智能路由器·运维开发
全栈小52 分钟前
【数据库】当InfluxDB遇到天花板:金仓数据库如何重构时序性能极限?
数据库·重构
颜颜yan_15 分钟前
时序数据库性能较量:金仓数据库如何在高负载场景中领跑InfluxDB
数据库·时序数据库
北友舰长17 分钟前
基于Springboot+thymeleaf快递管理系统的设计与实现【Java毕业设计·安装调试·代码讲解】
java·spring boot·mysql·校园管理·快递·快递系统
yfs102422 分钟前
PostgreSQL 16 + pgvector 完整安装和内网访问指南(Ubuntu 20.04)
数据库·ubuntu·postgresql
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ30 分钟前
查询MySQL数据库表的结构和数据
数据库·mysql·oracle
脸大是真的好~36 分钟前
MYSQL与B+树与索引相关面试题
数据库·b树·mysql
云和数据.ChenGuang36 分钟前
ELK 是一套**开源的日志收集、存储、分析与可视化的技术栈
服务器·数据库·elk·开源·运维技术·数据库运维工程师
risc12345637 分钟前
【Elasticsearch】副本恢复机制文件级(file-based)操作级(ops-based)顶级理解
java·mysql·lucene
MoonBit月兔39 分钟前
海外开发者实践分享:用 MoonBit 开发 SQLC 插件(其一)
数据库·缓存·wasm·moonbit