MySQL is a widely used relational database management system. In the process of using MySQL, we often encounter the problem of slow query speed. This may be caused by incorrect timeout settings. Therefore, in this article, we will introduce how to set the MySQL timeout time to better solve the problem of slow query speed.
MySQL timeout means that when performing certain operations, if the timeout has been reached, MySQL will actively disconnect the client. For example, when executing a query operation, if the query results take too long to return, the program may wait for a long time. This waiting time is called the timeout. Whether the timeout setting is reasonable or not is directly related to the performance and stability of the MySQL server.
Let’s introduce the setting method of MySQL timeout in detail:
1. View the timeout time
For MySQL5.1 version and later versions, you can use the following command to view MySQL Timeout:
show variables like 'wait_timeout';
This command will output the current timeout of MySQL.
2. Modify the timeout period
MySQL's timeout period can be modified through the command line or configuration file.
Command line method:
mysql> set global wait_timeout=600;
This command changes the MySQL timeout to 600 seconds.
Configuration file method:
In the configuration file, the timeout can be set by modifying the corresponding parameters in the my.cnf configuration file. The location of the file is usually located in /etc under the MySQL installation directory. /mysql/my.cnf.
After opening the my.cnf file, add the following code under [mysqld]:
wait_timeout=600
Then save the file and restart the MySQL service That’s it.
Summary
The setting of MySQL timeout involves the performance and stability of the MySQL server. Therefore, you must pay attention to setting the MySQL timeout when using MySQL. We can use the command line and configuration files to set the MySQL timeout, but we need to pay special attention to making sure it is not too small when modifying the timeout, otherwise it may affect the performance of the MySQL server.
The above is the detailed content of How to set mysql timeout. For more information, please follow other related articles on the PHP Chinese website!