Mysql 8-hour Solution

Source: Internet
Author: User

The mysql 8-hour solution can solve this problem in three ways: 1. Increase the value of the wait_timeout attribute of MySQL. Modify the/etc/mysql/my. cnf file at www.2cto.com and set the Java code in [mysqld ].
At the same time, only one of these two parameters works. Which parameter takes effect depends on the connection parameter specified during user connection. wait_timeout is used by default. I suggest modifying both parameters to avoid unnecessary troubles. The default values of the parameters www.2cto.com are 8 hours (60*60*8 = 28800 ). I tested changing these two parameters to 0, and the result is unexpected. The system automatically sets this value. In other words, you cannot set this value to permanent. Set these two parameters to 24 hours (60*60*24 = 604800. Set interactive_timeout = 604800; set wait_timeout = 604800; 2. Reduce the connection life cycle in the connection pool so that it is less than the value of wait_timeout set in the previous item. Modify the configuration file of c3p0 and set: # How long to keep unused connections around (in seconds) # Note: MySQL times out idle connections after 8 hours (28,800 seconds) # so ensure this value is below MySQL idle timeout cpool. maxIdleTime = 25200 in the Spring configuration file: the code is as follows: Java code <bean id = "dataSource" class = "com. mchange. v2.c3p0. comboPooledDataSource "> <property name =" maxIdleTime "value =" $ {cpool. maxIdleTime} "/> <! -- Other properties --> </bean> 3. regularly use connections in the connection pool so that they are not broken by MySQL due to idle timeout. Modify the configuration file of c3p0 and set: www.2cto.com # Prevent MySQL raise exception after a long idle timecpool. preferredTestQuery = 'select 1' cpool. idleConnectionTestPeriod = 18000cpool. testConnectionOnCheckout = true modify the Spring configuration file: the code is as follows: Java code <bean id = "dataSource" class = "com. mchange. v2.c3p0. comboPooledDataSource "> <property name =" preferredTestQuery "value =" $ {cpool. preferredTestQuery} "/> <property name =" idleConnectionTes TPeriod "value =" $ {cpool. idleConnectionTestPeriod} "/> <property name =" testConnectionOnCheckout "value =" $ {cpool. testconnectioncheckout} "/> <! -- Other properties --> </bean>

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.