MySQL connection Timeout: Automatic disconnection

Source: Internet
Author: User

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

 

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.