我正在尝试测试wait_timeout
MySQL 设置似乎被忽略了。
PHP 脚本:
<?php
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$sql = mysqli_connect('localhost','root','root','mysql');
$query = "SHOW VARIABLES WHERE Variable_name='wait_timeout';";
$result = $sql->query($query) or die($query.'<br />'.$sql->error);
$row = $result->fetch_object();
echo "wait_timeout = " . $row->Value . "<br/>\n";
$time_start = microtime_float();
$query = "SELECT SLEEP(2) FROM mysql.user;";
$sql->query($query) or die($query.'<br />'.$sql->error);
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "Query completed in $time seconds<br/>\n";
echo "You got the page";
脚本输出:
wait_timeout = 2
Query completed in 8.0005459785461 seconds
You got the page
我的配置
mariadb-server-5.3.5
php5.3.6
我需要做什么才能强制 MySQL 在一定时间后超时查询?
Both wait_timeout
and interactive_timeout
是连接断开之前不活动的时间。因此,连接在被删除之前必须处于空闲状态(未运行查询)。 MySQLSLEEP()
不算数,因为您正在运行查询。
您必须手动终止长时间运行的查询(没有设置让 MySQL 为您执行此操作)。您可以编写此脚本。使用SHOW PROCESSLIST
(或外部工具,如Innotop http://code.google.com/p/innotop/) and KILL
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)