了解“SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST”的结果
我想确保我的 php 代码和我的网站不使用永久连接。
我使用下面的sql查询来检查,但我不太明白输出,
$sql = "SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST";
$items = $connection -> fetch_all($sql);
print_r($items);
下面是输出,
Array
(
[0] => Array
(
[ID] => 43
[USER] => root
[HOST] => localhost:52246
[DB] => xxx_2010
[COMMAND] => Query
[TIME] => 0
[STATE] => executing
[INFO] => SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST
)
[1] => Array
(
[ID] => 38
[USER] => root
[HOST] => localhost:52140
[DB] =>
[COMMAND] => Sleep
[TIME] => 423
[STATE] =>
[INFO] =>
)
)
当我点击另一个页面时,
Array
(
[0] => Array
(
[ID] => 44
[USER] => root
[HOST] => localhost:52301
[DB] => xxx_2010
[COMMAND] => Query
[TIME] => 0
[STATE] => executing
[INFO] => SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST
)
[1] => Array
(
[ID] => 38
[USER] => root
[HOST] => localhost:52140
[DB] =>
[COMMAND] => Sleep
[TIME] => 1026
[STATE] =>
[INFO] =>
)
)
为什么它总是输出两个数组? [COMMAND]
中的 Query/Sleep 是什么意思?在[STATE]
中,它表示第一个数组中的executing
然后在第二个数组中变为空 - 这是否意味着一旦发送页面,数据库连接就会断开。
另外,[TIME] => 0 和 [时间] => 423 - 这是什么意思?
为什么有几个按键显示不同的值如[HOST] =>本地主机:52246,[主机] =>本地主机:52140, [ID] => 43、[ID]=> 38
等
抱歉,我可能只是问了一些愚蠢的问题...
谢谢。
编辑:
现在,在浏览器上关闭 phpMyadmin 后,我在输出中看到了这个,
Array
(
[0] => Array
(
[ID] => 59
[USER] => root
[HOST] => localhost:53195
[DB] => xxx_2010
[COMMAND] => Query
[TIME] => 0
[STATE] => executing
[INFO] => SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST
)
)
所以每当我在我的网站上单击时,它总是返回 [STATE] =>;正在执行
- 这是否意味着我的网站处于永久连接状态?
I want to make sure my php code and my website does not use permanent connections.
I use the sql query below to check but I don't quite understand the output,
$sql = "SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST";
$items = $connection -> fetch_all($sql);
print_r($items);
Below is the output,
Array
(
[0] => Array
(
[ID] => 43
[USER] => root
[HOST] => localhost:52246
[DB] => xxx_2010
[COMMAND] => Query
[TIME] => 0
[STATE] => executing
[INFO] => SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST
)
[1] => Array
(
[ID] => 38
[USER] => root
[HOST] => localhost:52140
[DB] =>
[COMMAND] => Sleep
[TIME] => 423
[STATE] =>
[INFO] =>
)
)
when I clicked on another page,
Array
(
[0] => Array
(
[ID] => 44
[USER] => root
[HOST] => localhost:52301
[DB] => xxx_2010
[COMMAND] => Query
[TIME] => 0
[STATE] => executing
[INFO] => SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST
)
[1] => Array
(
[ID] => 38
[USER] => root
[HOST] => localhost:52140
[DB] =>
[COMMAND] => Sleep
[TIME] => 1026
[STATE] =>
[INFO] =>
)
)
Why is it always output two arrays? What does it mean by Query/Sleep in the [COMMAND]
? in the [STATE]
it says executing
in the first array then became empty in the second array - does it mean that the db connection disconnects once the page has been sent.
Also, [TIME] => 0 and [TIME] => 423
- what does it mean?
Why there are a few keys display different values such as [HOST] => localhost:52246, [HOST] => localhost:52140, [ID] => 43, [ID] => 38
, etc
Sorry I might have just asked some dumb questions...
Thanks.
EDIT:
Now I have this in the output after closing phpMyadmin on my browser,
Array
(
[0] => Array
(
[ID] => 59
[USER] => root
[HOST] => localhost:53195
[DB] => xxx_2010
[COMMAND] => Query
[TIME] => 0
[STATE] => executing
[INFO] => SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST
)
)
So whenever I click around on my site, it always returns [STATE] => executing
- does it mean that my site is on permanent connections?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有一个从
root
用户打开的连接,该连接已经空闲了一段时间(ID 相同,并且睡眠时间相当长)。有些东西已打开但尚未关闭它(可能是来自 PHPMyAdmin 的未关闭连接,或类似的东西)...您的应用程序未使用相同的连接(您可以从 ID 列中看到)。至于其他连接,您可以尝试
KILL
它并查看它是否返回。如果没有的话,我不会太担心。另一件事是,不要使用
root
登录 MySQL 服务器。创建一个具有有限权限的用户,并授予PROCESS 许可。但永远不要以完全权限用户的身份进行连接......You have one connection open from the
root
user that has been idle for quite some time (the ID is the same, and the sleep time is quite high). Something has it open and hasn't closed it (Perhaps an unclosed connection from PHPMyAdmin, or something like that)...Your application isn't using the same connection (you can see from the ID column). As far as the other connection you can try
KILL
ing it and seeing if it returns. If it doesn't, I wouldn't worry too much about it.One other thing, don't use
root
to login to a MySQL server. Create a user with limited permissions, and grant the PROCESS permission. But don't ever connect as a full-priveleged user...MySQL 文档 对所有这些给出了相当全面的解释fields
State 'Executing' 的意思正是它所说的(这是你的查询),'Sleep' 意味着线程正在等待来自客户端的新命令
The MySQL Documentation gives a pretty comprehensive explanation of all these fields
State 'Executing' means exactly what it says (this is your query), 'Sleep' means that the thread is waiting for a new command from the client