Summary of timeout methods for setting MySQL database connection Query

Source: Internet
Author: User

In mysql, we need to set the mysql database query and connection timeout time. We only need to modify the wait_timeout value. There are two ways to modify the wait_timeout value, one is to use cmd to modify the value, the other is in mysql my. modify the cnf configuration file. First open your MySql console, enter the password, and then enter the command to quietly why the SQL Code times out and copies the content to the clipboard

  1. Show global variables like 'wait _ timeout ';

Here we can see that wait_timeout is 28800, which is 8 hours. That is to say, the MySQL service will be disconnected after 8 hours of operation, and re-connection is required. When we connect to java program JDBC, we can make it automatically restored.
Interactive_timeout: The number of seconds before the server closes the interactive connection. Interactive clients are defined as clients that use the CLIENT_INTERACTIVE option in mysql_real_connect. For more information, see wait_timeout.
Wait_timeout
: The number of seconds before the server closes a non-interactive connection. When a thread starts, the wait_timeout value of the session is initialized based on the global wait_timeout value or the global interactive_timeout value, depending on the client type (defined by the connection option CLIENT_INTERACTIVE of mysql_real_connect (). See interactive_timeout.
In this case, the two variables are jointly controlled and must be modified. The value range of wait_timeout is 1-2147483 (Windows), 1-31536000 (linux), and interactive_time varies with wait_timeout. Their default values are 28800.
MySQL System variables are controlled by the configuration file. If the configuration file is not configured, the system uses the default value. The default value is 28800. You can only modify it in the configuration file. In Windows, the my. ini configuration file exists in % MySQL HOME %. After opening the file, add the following sentence. (Change to 388000 here) Save and quit. Restart the mysql service. It must be a restart of the system service. The Modification result is displayed: the configuration file in Linux is/etc/my. cnf. (Same as above)

 

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.