/ 中存储网

解决MySQL数据库查询超时的问题

2014-07-13 16:24:23 来源:中存储网
mysql>show variables like '%timeout';   
打印结果如下:
+----------------------------+-------+   
| Variable_name | Value |   
+----------------------------+-------+   
| connect_timeout | 5 |   
| delayed_insert_timeout | 300 |   
| interactive_timeout | 28800 |   
| net_read_timeout | 30 |   
| net_write_timeout | 60 |   
| slave_net_timeout | 3600 |   
| wait_timeout | 28800 |   
+----------------------------+-------+   
interactive_timeout 需在mysql_connect()设置CLIENT_INTERACTIVE选项后起作用,并被赋值为wait_timeout;
mysql>set wait_timeout = 10; 对当前交互链接有效;
mysql>set interactive_timeout = 10; 对后续起的交互链接有效;
该超时时间单位是秒,从变量从上次SQL执行后算起;当前空闲若超过该时间,则也会被强制断开。
interactive_timeout(常用)
The number of seconds the server waits for activity on an interactive connection before closing it. An interactive client is defined as a client that uses the CLIENT_INTERACTIVE option to mysql_real_connect(). See also wait_timeout.
译解:客户端和服务器交互的空闲超时时间。该系统变量仅当客户端连接服务器时设置了“MYSQL_CLIENT_INTERACTIVE”标志才生效,例如:
//启用MYSQL_CLIENT_INTERACTIVE模式,连接数据库服务器  
$link = mysql_connect($host, $user, $pwd, false, MYSQL_CLIENT_INTERACTIVE);