There are two main reasons for MySQL downtime:
1. Memory is heavily occupied by other processes, or the database itself is too large to cause MySQL downtime
2. Program access to MySQL did not perform mysql.close, a large number of resources caused downtime.
The problem raised in the group is mainly mysql5.5 or above, and is basically not MySQL downtime. Because more than 5.5 of the databases will have a link timeout configuration.
The default is 28,800 seconds and 8 hours, and the connection is disconnected.
Solution:
1. Modify the MySQL configuration.
If you are a Linux server editor mysql.cnf execute VI/ETC/MYSQL.CNF
Find [mysqld] to add underneath
interactive_timeout=28800000
wait_timeout=28800000
Three extra 0 is 8,000 hours. Basically, you don't have to consider the connection timeout
When you have finished modifying the configuration, remember to restart the MySQL service.
2. Procedural aspects.
Take the Java program for example (sorry only Java)
Open the spring configuration file and modify the Applicationcontext.xml
Add underneath the DataSource bean
Used to specify the SQL statement used by the test connection.
If the test discovers that the connection is close, the connection is automatically rebuilt.
<property name= "Housekeepingtestsql" >
<value>select 1</value>
</property>
Used to specify that tests should be performed before the connection is used.
<property name= "Testbeforeuse" >
<value>true</value>
</property>