Mysql数据库连接失败SSLException: Unsupported record version Unknown-0.0问题

 更新时间:2024年06月06日 10:24:19   作者:chgiser  
这篇文章主要介绍了Mysql数据库连接失败SSLException: Unsupported record version Unknown-0.0问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

问题描述

  • mysql版本:5.7.27
  • jdk版本:1.8.0_201

tomcat日志中报错,显示连接数据库失败,报错信息如下:

The last packet successfully received from the server was 152 milliseconds ago.  The last packet sent successfully to the server was 147 milliseconds ago.
    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:404)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:981)
    at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:164)
    ... 89 more
Caused by: javax.net.ssl.SSLException: Unsupported record version Unknown-0.0
    at sun.security.ssl.InputRecord.checkRecordVersion(InputRecord.java:552)
    at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:565)
    at sun.security.ssl.InputRecord.read(InputRecord.java:529)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
    at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:149)
    ... 89 more
Mon Dec 09 13:15:02 CST 2019 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.
2019-12-09 13:15:02,494 ERROR [com.alibaba.druid.pool.DruidDataSource] - <create connection error, url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8, errorCode 0, state 08S01>
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

解决方法

显示配置数据库连接地址useSSL=false,如

jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8&useSSL=false

问题延伸

另一种比较麻烦的问题是geoserver也出现了类似连接mysql异常的问题,

报错信息如下:

ERROR [geoserver.ows] - 
java.lang.RuntimeException: Error getting FeatureType, this should never happen!
    at org.geoserver.wms.map.GetMapKvpRequestReader.checkStyle(GetMapKvpRequestReader.java:1218)
    at org.geoserver.wms.map.GetMapKvpRequestReader.read(GetMapKvpRequestReader.java:566)
    ... 100 more
Caused by: java.io.IOException
    at org.geoserver.catalog.ResourcePool.getDataStore(ResourcePool.java:632)
    at org.geoserver.catalog.ResourcePool.getCacheableFeatureType(ResourcePool.java:916)
    at org.geoserver.catalog.ResourcePool.tryGetFeatureType(ResourcePool.java:901)
    at org.geoserver.catalog.ResourcePool.getFeatureType(ResourcePool.java:893)
    at org.geoserver.catalog.ResourcePool.getFeatureType(ResourcePool.java:878)
    ... 111 more
Caused by: java.lang.RuntimeException: Unable to obtain connection: Cannot create PoolableConnectionFactory (Communications link failure

The last packet successfully received from the server was 2 milliseconds ago.  The last packet sent successfully to the server was 2 milliseconds ago.)
    at org.geotools.jdbc.JDBCDataStore.createConnection(JDBCDataStore.java:2186)
    at org.geotools.jdbc.JDBCDataStore.createTypeNames(JDBCDataStore.java:978)
    at org.geotools.data.store.ContentDataStore.getTypeNames(ContentDataStore.java:259)
    at org.vfny.geoserver.util.DataStoreUtils.getDataAccess(DataStoreUtils.java:88)
    at org.geoserver.catalog.ResourcePool.getDataStore(ResourcePool.java:591)
    ... 115 more
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

The last packet successfully received from the server was 2 milliseconds ago.  The last packet sent successfully to the server was 2 milliseconds ago.)
    at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
    at org.geotools.data.jdbc.datasource.AbstractManageableDataSource.getConnection(AbstractManageableDataSource.java:41)
    at org.geotools.jdbc.JDBCDataStore.createConnection(JDBCDataStore.java:2170)
    ... 119 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 2 milliseconds ago.  The last packet sent successfully to the server was 2 milliseconds ago.
    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.SQLError.createCommunicationsException(SQLError.java:990)
    ... 143 more
Caused by: javax.net.ssl.SSLException: Unsupported record version Unknown-0.0
    at sun.security.ssl.InputRecord.checkRecordVersion(InputRecord.java:552)
    at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:565)
    at sun.security.ssl.InputRecord.read(InputRecord.java:529)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
    at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:186)
    ... 142 more

查找了geoserver中mysql插件的相关配置项,没有找到设置SSL连接的属性,在不修改geoserver源码的情况下,只能修改mysql的ssl配置来修复了,

在mysql的配置文件my.cnf中加上一行:

# disable_ssl
skip_ssl

重启MySQL:

service mysqld restart

再查看SSL的开启状态:

SHOW VARIABLES LIKE '%ssl%';

看到have_ssl的值为DISABLED,表示已关闭SSL。

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • MySQL数据库基础学习之JSON函数各类操作详解

    MySQL数据库基础学习之JSON函数各类操作详解

    很多日常业务场景都会用到json文件作为数据存储起来,而mysql5.7以上就提供了存储json的支撑。这篇文章就为大家整理了MySQL中JSON函数的各类操作,感兴趣的可以了解一下
    2023-02-02
  • MySQL随机获取一条记录的方法小结

    MySQL随机获取一条记录的方法小结

    随机获取一条记录是在数据库查询中常见的需求,在 MySQL 中,有多种方法可以实现随机获取一条记录,每种方法都有其适用的情况和性能特点,在本文中,我们将探讨几种常用的方法,并推荐适合不同情况下的最佳方法,需要的朋友可以参考下
    2024-04-04
  • 解决MySQL报错1267 - Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_general_ci,IMPL问题

    解决MySQL报错1267 - Illegal mix of coll

    这篇文章主要给大家介绍了解决MySQL报错1267 - Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_general_ci,IMPL的问题,文中有详细的解决方案,需要的朋友可以参考下
    2023-09-09
  • 浅谈mysql密码遗忘和登陆报错的问题

    浅谈mysql密码遗忘和登陆报错的问题

    下面小编就为大家带来一篇浅谈mysql密码遗忘和登陆报错的问题。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-03-03
  • MySQL OOM 系统二 OOM Killer

    MySQL OOM 系统二 OOM Killer

    前面一节重点分享了Linux的内存分配策略,基于上述的分配策略,为了规避超售的风险,Linux采了一种OOM Killer的机制,即系统可用内存(包括Swap)即将使用完之前,选择性的Kill掉一些进程以求释放一些内存
    2016-07-07
  • 修改MySQL所有表的编码或修改某个字段的编码步骤详解

    修改MySQL所有表的编码或修改某个字段的编码步骤详解

    这篇文章主要给大家介绍了关于修改MySQL所有表的编码或修改某个字段编码的相关资料,在进行数据库编码更改之前,需要先确定目标编码格式,常见的编码格式有UTF-8、GBK等,需要的朋友可以参考下
    2023-12-12
  • 找到MySQL的优点

    找到MySQL的优点

    假设你是一个Access开发人员,而你想移植一个Access后台到一个本地的MySQL 服务器用于开发和测试。你将维护你自己的解决方案并乐于使用Community Server
    2009-09-09
  • MySQL 序列 AUTO_INCREMENT详解及实例代码

    MySQL 序列 AUTO_INCREMENT详解及实例代码

    这篇文章主要介绍了MySQL 序列 AUTO_INCREMENT详解及实例代码的相关资料,需要的朋友可以参考下
    2017-02-02
  • mysql复制data文件迁移的实现步骤

    mysql复制data文件迁移的实现步骤

    有时候,我们需要迁移整个数据库,包括数据文件,本文将介绍如何通过复制MySQL的data文件来完成数据库迁移,具有一定的参考价值,感兴趣的可以了解一下
    2023-11-11
  • MySQL数据库中的TRUNCATE TABLE命令详解

    MySQL数据库中的TRUNCATE TABLE命令详解

    这篇文章主要给大家介绍了关于MySQL数据库中TRUNCATE TABLE命令的相关资料,Truncate Table“清空表”的意思,它对数据库中的表进行清空操作,文中通过代码介绍的非常详细,需要的朋友可以参考下
    2024-05-05

最新评论