MySQL - 如何仅使用当前用户的进程显示 PROCESSLIST?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/334280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL - how to SHOW PROCESSLIST only with current user's processes?
提问by Piskvor left the building
Is there a way in MySQL 5 to show only the current user's processes(queries)?
MySQL 5 有没有办法只显示当前用户的进程(查询)?
The user has the PROCESS
privilege, therefore SHOW PROCESSLIST
displays running processes of all users. According to the documentation, SHOW PROCESSLIST
does not allow any kind of WHERE
syntax, nor did I manage to make it into a subquery.
用户有PROCESS
权限,因此SHOW PROCESSLIST
显示所有用户正在运行的进程。根据文档,SHOW PROCESSLIST
不允许使用任何类型的WHERE
语法,我也没有设法将其变成子查询。
Of course, I could simply send the query, e.g. in a PHP script, and go through the results in a loop, discarding everything that's not mine, but it seems rather inefficient. Changing the user privileges is not feasible.
当然,我可以简单地发送查询,例如在 PHP 脚本中,然后在循环中检查结果,丢弃所有不属于我的内容,但这似乎效率很低。更改用户权限是不可行的。
Are there any other ways? Thanks in advance.
还有其他方法吗?提前致谢。
回答by Bill Karwin
If you use MySQL 5.1.7 or newer, you can use the PROCESSLISTtable in the INFORMATION_SCHEMA. So you can query it with ordinary SELECT
queries and apply filtering conditions in a WHERE
clause.
如果您使用 MySQL 5.1.7 或更新版本,则可以使用INFORMATION_SCHEMA 中的PROCESSLIST表。因此,您可以使用普通SELECT
查询来查询它并在WHERE
子句中应用过滤条件。
This feature is not implemented in MySQL 5.0 and prior.
此功能在 MySQL 5.0 及更早版本中未实现。
回答by staticsan
If the user does not have PROCESS
, then SHOW PROCESSLIST
will only show their own threads.
如果用户没有PROCESS
,则SHOW PROCESSLIST
只会显示自己的线程。