记一次数据库连接 bug

整个的报错如下:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

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.Util.getInstance(Util.java:408)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861)

at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2105)

at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2030)

at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:778)

at com.mysql.jdbc.JDBC4Connection.(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:386)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)

at java.sql.DriverManager.getConnection(DriverManager.java:664)

at java.sql.DriverManager.getConnection(DriverManager.java:247)

at com.baomidou.mybatisplus.generator.config.DataSourceConfig.getConn(DataSourceConfig.java:171)

at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.handlerDataSource(ConfigBuilder.java:287)

at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.(ConfigBuilder.java:139)

at com.baomidou.mybatisplus.generator.AutoGenerator.execute(AutoGenerator.java:88)

at cn.itcast.haoke.generator.CodeGenerator.main(CodeGenerator.java:106)

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 1 milliseconds ago. The last packet sent successfully to the server was 1 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)

at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:201)

at com.mysql.jdbc.MysqlIO.negotiateSSLConnection(MysqlIO.java:4914)

at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1663)

at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1224)

at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2199)

at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2046)

... 17 more

Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

at sun.security.ssl.HandshakeContext.(HandshakeContext.java:171)

at sun.security.ssl.ClientHandshakeContext.(ClientHandshakeContext.java:106)

at sun.security.ssl.TransportContext.kickstart(TransportContext.java:245)

at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:410)

at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:389)

at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:186)

... 22 more

Exception in thread "main" java.lang.NullPointerException

at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.getTablesInfo(ConfigBuilder.java:469)

at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.handlerStrategy(ConfigBuilder.java:301)

at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.(ConfigBuilder.java:146)

at com.baomidou.mybatisplus.generator.AutoGenerator.execute(AutoGenerator.java:88)

at cn.itcast.haoke.generator.CodeGenerator.main(CodeGenerator.java:106)

最最主要的就是这个位置的报错,这个信息是关于 MySQL 数据库在不同版本中对 SSL 连接的默认要求。具体来说,从 MySQL 5.5.45、5.6.26 和 5.7.6 版本开始,如果在连接字符串中没有明确指定 SSL 选项,MySQL 会默认要求建立 SSL 连接。这意味着,如果你的客户端(如 Java 应用程序)在连接 MySQL 数据库时没有明确指定 SSL 选项,连接可能会失败,因为服务器会要求使用 SSL 加密连接

解决方法:

在开发环境下大家直接在链接的位置这样设置就好,将userSSL设置为false

bash 复制代码
jdbc:mysql://localhost:3306/your_database?useSSL=false&serverTimezone=UTC

如果在生产环境,一定记得使用 SSL 认证的方式去连接

相关推荐
TU不秃头1 小时前
SQL面试题2:留存率问题
数据库·sql
xiaolin03331 小时前
ElasticSearch下
数据库·elasticsearch
dal118网工任子仪1 小时前
58,【8】BUUCTF [PwnThyBytes 2019]Baby_SQL1
数据库·笔记·sql·学习·mysql
MissYou-Coding3 小时前
MySQL无限极分类表设计:实战项目中的高效解决方案
数据库·mysql
糯米汤圆~3 小时前
MySQL备份案例: mysqldump+binlog实现完全+增量备份
linux·运维·数据库·mysql
零臣3 小时前
使用Redis防止重复发送RabbitMQ消息
java·数据库·redis·rabbitmq
V+zmm101343 小时前
小程序疫苗预约网站系统ssm+论文源码调试讲解
java·数据库·微信小程序·小程序·毕业设计
m0_748236833 小时前
MySQL 的mysql_secure_installation安全脚本执行过程介绍
数据库·mysql·安全
黄交大彭于晏3 小时前
b站视频(网页加客户端)+本地视频 生成回链
数据库·redis·音视频
betazhou3 小时前
oracle goldengate from mongodb to oracle的实时同步
数据库·mongodb·oracle