Install MySQL more than 5.5 often found that the site does not access the database

Source: Internet
Author: User

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>

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.