mysql-connector-java 8.0.26 以上版本无法连接数据库的原因及解决方法 Could not create connection to database server.

编程入门 行业动态 更新时间:2024-10-15 12:37:15

由于SpringBoot2.5.3版本之后内置的mysql-connector-java版本升级为8.0.26,但是该版本的mysql-connector-java进行了一个影响较大的改动,导致部分用户无法启动SpringBoot。

报错信息通常如下:

java.lang.ArrayIndexOutOfBoundsException: 8

或者

Could not create connection to database server. Attempted reconnect 3 times.

通过这些报错信息在网上进行查询,通常查询得出的结果是,连接字符串中没有设置时区,或者直接建议你降低版本到8.0.25及以下。但是由于mysql-connector-java 8.0.27版本修复了一个严重的安全漏洞,所以不建议使用8.0.27以下的低版本mysql-connector-java,这也是导致springboot在新版中使用8.0.27版本mysql-connector-java的原因。

1. 问题原因

从字面意思根本无法得知该问题的原因,通过查看MySQL Connector/J 8.0.26在2021-07-20发布的更新公告中,可以看到该版本弃用了一些功能和特性,其中就包括TLSv1协议和TLSv1.1协议。

以下是原文:

Deprecation and Removal Notes

  • The TLSv1 and TLSv1.1 connection protocols are now deprecated. While connections to the server using those TLS versions can still be made with the same negotiation process as before, for any connections established using those TLS versions, Connector/J writes to its logger the message "This connection is using TLSv1[.1] which is now deprecated and will be removed in a future release of Connector/J."

    For background to this deprecation, refer to the IETF memo Deprecating TLSv1.0 and TLSv1.1. It is recommended that connections be made using the more-secure TLSv1.2 and TLSv1.3 protocols.

以下是翻译: 

弃用和删除说明

  • TLSv1 和 TLSv1.1 连接协议现已弃用。虽然使用这些 TLS 版本与服务器的连接仍然可以使用与以前相同的协商过程进行,但对于使用这些 TLS 版本建立的任何连接,Connector/J 会向其记录器写入消息“此连接正在使用 TLSv1[.1]现在已弃用,并将在将来的 Connector/J 版本中删除。”

    有关此弃用的背景信息,请参阅 IETF 备忘录 Deprecating TLSv1.0 and TLSv1.1。建议使用更安全的 TLSv1.2 和 TLSv1.3 协议进行连接。

 2. 解决方法

        所以我们需要检查项目的jdbc连接字符串,将useSSL=false更改为useSSL=true,更改后重新启动,即可完成连接了。

        注:如果更改useSSL为true之后,连接时产生了异常,那么应该是你的数据库没有开启SSL功能或没有配置SSL证书,生成并配置一下SSL证书就可以正常连接了。

更多推荐

mysql-connector-java 8.0.26 以上版本无法连接数据库的原因及解决方法 Could not create connection to d

本文发布于:2023-06-14 09:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463009.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:解决方法   连接数据库   原因   版本   connector

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!