MySQL reconnection, connection loss issue: The last packet sent successfully to the server was ...

Source: Internet
Author: User

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 ...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.