[Solved] MYSQL Connect Error: 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.

When we report the first few lines of error information as shown in the figure above, we can try to exclude common errors on the Internet as below:
1. MySQL data service is not enabled
2. serverTimezone parameter
3. wait_timeout settings

If the error is still reported, check whether there is this line after the error message
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

Solution:
add the parameter usessl = false to the URL

jdbc:mysql://xxx.xxx.xxx.xxx/db?useSSL=false

Cause:
Communications link failure
Caused by: javax.net.ssl
Before MySQL 5.7, the security was low and there were test libraries that any user could connect to, so the official version 5.7 increased the privacy protection. The default value of useSSL = true was used to prevent arbitrary changes to the database. In version 8.0, SSL is still retained and the default value is true, so just set “?useSSL= false” and you’re done!

Read More: