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