There are two main reasons for mysql downtime:
1. The memory is heavily occupied by other processes, or the database data volume is too large, leading to mysql downtime
2. After the program accesses mysql, it does not execute mysql. close, which occupies a large amount of resources and leads to downtime.
The main problem raised in the group is mysql5.5 or above, basically not mysql downtime. Because more than 5.5 of databases have a connection timeout configuration.
The default value is 28800 seconds, that is, 8 hours. The connection is closed.
Solution:
1. Modify the mysql configuration.
On the linux server, edit mysql. cnf and run vi/etc/mysql. cnf.
Find [mysqld] and add it under
Interactive_timeout = 28800000
Wait_timeout = 28800000
Three more zeros are added, that is, 8000 hours. Basically, you don't need to consider connection timeout.
After modifying the configuration, restart the mysql service.
2. Procedures.
Take the java program as an example (Sorry, only java is used)
Open the Spring configuration file and modify applicationContext. xml.
Add under datasource bean
Specifies the SQL statement used to test the connection.
If the connection is closed, the connection is automatically rebuilt.
<Property name = "houseKeepingTestSql">
<Value> SELECT 1 </value>
</Property>
Used to specify that a test is required before the connection is used.
<Property name = "testBeforeUse">
<Value> true </value>
</Property>