1.log error log:
-org.hibernate.exception.jdbcconnectionexception:the last packet successfully received from the server was 51,999,860 mi Lliseconds ago. The last packet sent successfully to the server was 51,999,860 milliseconds ago. is longer than the server configured value of ' Wait_timeout '. Should consider either expiring and/or testing connection validity before use in your application, increasing the Serv Er configured values for client timeouts, or using the Connector/j Connection property ' Autoreconnect=true ' to avoid this Problem.
The error will also prompt you to modify Wait_timeout or use Connector/j's AutoReConnect property to avoid the error.
Later looked up some information, only to find that the problem encountered a lot of people, most of them are using the connection pool mode when this problem occurs, short connection should be difficult to appear this problem.
2. The cause of this problem:
MySQL server default "Wait_timeout" is 28,800 seconds, that is 8 hours,
means that if a connection is idle for more than 8 hours, MySQL will automatically disconnect the connection,
The connection pool considers the connection to be valid (because the validity of the connection is not verified), which results in an error when the application requests the connection.
3. Workaround:
A. Follow the wrong prompts, you can use the AutoReConnect property in the JDBC URL, here is my configuration
<property name= "Connection.url" >
Jdbc:mysql://localhost:3306/anxincar? autoreconnect=true
</property>
Where the red part is the newly added property setting
However, there is another version of the Internet, it has been tested that the setting is only valid for versions prior to MYSQL4, and whether it is true or not is yet to be verified.
B. I looked under the mysql5.0 installed on our server, in order to ensure that the connection is no longer lost and this problem occurs, while modifying the MySQL parameters, wait_timeout maximum of 31536000 that is 1 years, in My.ini added:
[Mysqld]
wait_timeout=31536000
interactive_timeout=31536000
The red part is the newly added parameter setting
Finally: Restart the MySQL service and restart Tomcat for the configuration file to take effect.
MySQL reconnection, connection loss problem: The last packet sent successfully to the server was ...