MySQL connection timeout automatic disconnection Problem description: when using mybatis2.3.5 for application implementation, the program reports the following error: com. mysql. jdbc. exceptions. jdbc4.CommunicationsException: The last packet successfully encoded ed from the server was 79,221,885 milliseconds ago. the last packet sent successfully to the server was 79,221,885 milliseconds ago. is longer than the server configured value of 'wait _ timeout '. you shoshould consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoreconnect = true' to avoid this problem. explanation and solution: If the connection is idle for 8 hours (the default time of the wait_timeout parameter of mysql), mysql will automatically disconnect and refresh the application. without hibernate, the connection url is added with parameters:
autoReconnect=true
If hibernate is used, add the following attributes:
<property name="connection.autoReconnect">true</property> <property name="connection.autoReconnectForPools">true</property> <property name="connection.is-connection-validation-required">true</property>
If you still use the c3p0 connection pool:
<property name="hibernate.c3p0.acquire_increment">1</property> <property name="hibernate.c3p0.idle_test_period">0</property> <property name="hibernate.c3p0.timeout">0</property> <property name="hibernate.c3p0.validate">true</property>
Example:
jdbc.url=jdbc:mysql://localhost:3306/yht_wxt?zeroDateTimeBehavior=convertToNull&useUnicode=True&characterEncoding=utf8&autoReconnect=true&autoReconnectForPools=true