The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received


載自:https://blog.csdn.net/ponxbin/article/details/80608040

關於版本比較新的數據庫(Mysql8.0)連接的問題:

he last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:172)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:444)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at mysqlconnect.connect.main(connect.java:24)
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure


The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:59)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:103)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:149)
at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:165)
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:355)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:789)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:499)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:217)
at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1411)
at com.mysql.cj.NativeSession.connect(NativeSession.java:165)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:982)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:852)
... 6 more
Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:213)
at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:206)
at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99)
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:350)
... 13 more
Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
at com.mysql.cj.protocol.ExportControlled$X509TrustManagerWrapper.checkServerTrusted(ExportControlled.java:280)
at sun.security.ssl.AbstractTrustManagerWrapper.checkServerTrusted(Unknown Source)
... 25 more
Caused by: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
at sun.security.provider.certpath.PKIXCertPathValidator.validate(Unknown Source)
at sun.security.provider.certpath.PKIXCertPathValidator.engineValidate(Unknown Source)
at java.security.cert.CertPathValidator.validate(Unknown Source)
at com.mysql.cj.protocol.ExportControlled$X509TrustManagerWrapper.checkServerTrusted(ExportControlled.java:273)
... 26 more
Exception in thread "main" java.lang.NullPointerException
at mysqlconnect.connect.main(connect.java:34)

網上說的什么修改的方法對我沒有用

諸如此類:


1·修改my.ini bind-address = 127.0.0.1 為 bind-address = 0.0.0.0   使非本地網絡可以訪問數據庫

2·檢查防火牆是否有開放3306端口

3·網上廣為流傳的86400秒超時 回收機制 並不和我遇到的問題一致,這種問題是在程序運行過程中因為我們使用的連接池不知道連接被回收了所以報出的異常,解決方案可以是修改連接池配置或修改mysql空閑超時時間配置。

以上方法均沒用,主要是mysql和驅動版本的問題

我的mysql是8.0,驅動也是8.x最新的;

Class.forName("com.mysql.cj.jdbc.Driver");

url = "jdbc:mysql://localhost:3306/jnditest?serverTimezone=GMT&useSSL=false";//數據庫的路徑

主要是紅色字體方面,serverTimezone缺失是很容易從錯誤找出來的,但是重點是useSSL=false,這個從錯誤提示是看不出來的,它有個很重要的作用是使用JDBC跟你的數據庫連接的時候,你的JDBC版本與MySQL版本不兼容,MySQL的版本更高一些,在連接語句后加上“useSSL=‘true’” ,就可以連接到數據庫了。更高版本。但如果是兼容版本的話就會出錯。

我試了改成true的確又出現了這個問題。
————————————————
版權聲明:本文為CSDN博主「重新學習java」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/ponxbin/article/details/80608040


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. 【異常】The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. Communications link failure;;The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. The last packet successfully received from the server was 20,519 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago. 解決MySql - Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. 的問題 docker自制jar包鏡像運行容器報(The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.) mysql 連接池連接超時的問題(The last packet successfully received from the server was 2,431 milliseconds ago. The last packet sent successfully to the server was 2,417 milliseconds ago.)
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM