MySQL Variables connect_timeout 数据库 参数变量解释及正确配置使用
本站中文解释
connect_timeout(连接超时)是MySQL服务器向客户端响应title请求的最长时间,单位为秒。如果响应超过这个时间,客户端会收到一个“超时”错误,并且连接会被关闭。这个参数默认为10秒。
可以通过在配置文件中设置来更改这个参数,或者可以在每次连接时设置,例如:
// 设置connect_timeout到20秒
mysql -h host -u username -p –connect-timeout=20
另外,也可以在程序中设置connect_timeout:
// 使用PHP来设置connect_timeout
$link = mysqli_init();
$timeout = 20;
mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, $timeout);
官方英文解释
connect_timeout
| Command-Line Format | --connect-timeout=# |
|---|---|
| System Variable | connect_timeout |
| Scope | Global |
| Dynamic | Yes |
| Type | Integer |
| Default Value | 10 |
| Minimum Value | 2 |
| Maximum Value | 31536000 |
| Unit | seconds |
The number of seconds that the mysqld
server waits for a connect packet before responding with
Bad handshake. The default value is 10
seconds.
Increasing the
connect_timeout value might
help if clients frequently encounter errors of the form
Lost connection to MySQL server at.
'XXX', system error:
errno