最大MySQL连接数,适当关闭连接

时间:2016-10-12 05:42:50

标签: mysql multithreading

我正在开发一个Web应用程序(小部件),我正在研究程序处理MySQL连接的方式。添加一些调试代码来监控状态,我得到这样的结果:

$query = 'SHOW STATUS WHERE variable_name LIKE "Threads_%" OR variable_name = "Connections"';
$result = mysqli_query($GLOBALS["___mysqli_ston"], $query);
while ($row = mysqli_fetch_array($result)) {
echo print_r($row);
}

数组([0] =>连接[Variable_name] =>连接[1] => 1368 [值] => 1368)1Array([0] => Threads_cached [Variable_name] => Threads_cached [1] => 0 [Value] => 0)1Array([0] => Threads_connected [Variable_name] => Threads_connected [1] => 1 [Value] => 1)1Array([0 ] => Threads_created [Variable_name] => Threads_created [1] => 1367 [Value] => 1367)1Array([0] => Threads_running [Variable_name] => Threads_running [1] => 1 [值] => 1)1

创建的连接和线程不断增加,但运行的线程始终保持为1。我看着SHOW VARIABLES LIKE' max_user_connections'在服务器上,它被设置为0.创建这么多的连接和线程是一个问题吗?

感谢。

1 个答案:

答案 0 :(得分:0)

变量连接 Threads_created 始终是递增计数器。如果您想查看当前连接 - 请使用 Threads_connected 变量,或发出查询SHOW FULL PROCESSLIST