Site multiple sleep connection, MySQL connection number is insufficient, resulting in access blocked or inaccessible problem resolution

Source: Internet
Author: User
Tags java web

The workaround is to set the value of the following two parameters, which is to automatically clear the sleep connection after the expiration time

Interactive_timeout:
Parameter meaning: The number of seconds that the server waits for activity before closing an interactive connection. The interactive client is defined as a client that uses the Client_interactive option in Mysql_real_connect ().
Parameter default value: 28,800 seconds (8 hours)

Wait_timeout:
Parameter meaning: The number of seconds that the server waits for activity before closing a non-interactive connection.
Parameter default value: 28,800 seconds (8 hours)

How to view these two values
Show global variables like '%timeout% '

When a thread starts, the session timeout value is initialized based on the global Wait_timeout value or global interactive_timeout value, depending on the client type (the connection option by Mysql_real_connect () Client_ Interactive definition).
That is, the global wait_timeout determines the timeout value of the session (non-interactive connection), and the global interactive_timeout determines the timeout value of the session (interactive connection)

What is interactive and non-interactive?
Interactive operation: In layman's terms, you open the MySQL client on your local computer, that is, the Black window, under the Black window for various SQL operations, of course, the TCP protocol is definitely going.
Non-interactive: This is where you make program calls in your project. For example, one side is the Tomcat Web server, one side is the database server, how do they communicate? In the Java Web, we usually choose Hibernate or JDBC to connect. Then this is a non-interactive operation.

How do I set these two values? (Remember to add global globally (requires root user settings), not the default is the session)
Set Global wait_timeout=60
Set Global interactive_timeout=65

As set up, the site after the test is 65 seconds to be clear sleep connection, so your station if there is a lot of sleep connection, you can adjust this value, the length of time by the business to set, too short will be frequent connection, too long to occupy the connection.

And if the reverse
Set Global wait_timeout=65
Set Global interactive_timeout=60
Open the Navicat client using show variables like ' wait_timeout ' display of 60;
Use show global variables like ' wait_timeout ' to display 65.
or interactive_timeout to determine the timeout value of the session

Site multiple sleep connection, MySQL connection number is insufficient, resulting in access blocked or inaccessible problem resolution

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.