com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Solution

Table of contents

specific error message

Some programs on the Internet

solution


specific error message

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

The last packet successfully received from the server was 233 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.
 

Some programs on the Internet

Increase the wait_timeout of mysql

Use autoReconnect=true&failOverReadOnly=false, (only valid for versions before mysql 4)

The time in the error message of the above solutions is generally very large, such as

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

The last packet successfully received from the server was 1,548,635,756,564 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.

But my error is not a timeout, because wait_timeout is 8 hours by default, and the time in the error message is only 233ms.

solution

In this case you can try to

The Driver in the configuration file is set to com.mysql.cj.jdbc.Driver

com.mysql.jdbc.Driver is mybatis-connection-java 5 and below

com.mysql.cj.jdbc.Driver is mybatis-connection-Java 6 and above

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver

mysql dependency in pom can be set to version 6+

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.28</version>
</dependency>

After the modification, the project can run normally.

Guess you like

Origin blog.csdn.net/weixin_40757930/article/details/128997068