當我們報錯資訊前幾行如下: Communications link failure
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: 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 error may exist in mappers/UserMapper.xml
### The error may involve com.chunqiu.mybatis.mapper.UserMapper.insertUser
### The error occurred while executing an update
### Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: 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.
可以試着排除網上常見錯誤如:
1.mysql資料服務沒有開啟
2.serverTimezone參數
3.wait_timeout設定
如果仍然報錯,檢查一下報錯資訊後面有沒有這一行
Caused by: javax.net.ssl.SSLHandshakeException
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:171)
at sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:106)
at sun.security.ssl.TransportContext.kickstart(TransportContext.java:238)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:410)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:389)
at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:316)
at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188)
at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99)
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:352)
... 55 more
解決方法:
給url加上參數 useSSL=false
原因:
Communications link failure:通信鍊路故障
Caused by: javax.net.ssl
MySQL5.7之前的版本,安全性較低,存在任何使用者都可以連接配接上的 test 庫,是以官方在5.7版本加大了對隐私的保護。并且采用了預設 useSSL = true值防止對資料庫的随意修改,到了8.0版本,仍然保留了SSL,并且預設值為 true,是以隻要将"?useSSL= false"就可以了!