自学内容网 自学内容网

记一次数据库连接 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

jdbc:mysql://localhost:3306/your_database?useSSL=false&serverTimezone=UTC

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


原文地址:https://blog.csdn.net/qq_74212030/article/details/145211142

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!