If you install mysql 5.5 or above, you will often find that the website cannot access the database.

Source: Internet
Author: User

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>

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.