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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:28:01  来源:igfitidea点击:

MySQL - how to SHOW PROCESSLIST only with current user's processes?

mysql

提问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 PROCESSprivilege, therefore SHOW PROCESSLISTdisplays running processes of all users. According to the documentation, SHOW PROCESSLISTdoes not allow any kind of WHEREsyntax, 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 SELECTqueries and apply filtering conditions in a WHEREclause.

如果您使用 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 PROCESSLISTwill only show their own threads.

如果用户没有PROCESS,则SHOW PROCESSLIST只会显示自己的线程。