Mysql 所有没有 root 权限的用户进程列表

Mysql all user processlist without root permission

我需要 mysql 中的一个用户 运行 只有一个查询

SHOW PROCESSLIST;

并显示 mysql 中的所有用户进程列表(如 root 用户)并且此用户没有其他访问权限

我需要这个用户来调试查询。

我不想让 root 用户使用这个简单的查询!

有什么解决办法吗?

https://dev.mysql.com/doc/refman/8.0/en/show-processlist.html 说:

If you have the PROCESS privilege, you can see all threads, even those belonging to other users. Otherwise (without the PROCESS privilege), nonanonymous users have access to information about their own threads but not threads for other users, and anonymous users have no access to thread information.

让我们测试创建一个用户并只授予他们 PROCESS 权限:

mysql> create user 'testy'@'localhost' identified by 'testy';

mysql> grant process on *.* to 'testy'@'localhost';

mysql> exit

$ mysql -utesty -ptesty 

mysql> show processlist;
+----+-------+-----------+------+---------+------+----------+------------------+-----------+---------------+
| Id | User  | Host      | db   | Command | Time | State    | Info             | Rows_sent | Rows_examined |
+----+-------+-----------+------+---------+------+----------+------------------+-----------+---------------+
| 34 | testy | localhost | NULL | Query   |    0 | starting | show processlist |         0 |             0 |
+----+-------+-----------+------+---------+------+----------+------------------+-----------+---------------+

mysql> show grants;
+---------------------------------------------+
| Grants for testy@localhost                  |
+---------------------------------------------+
| GRANT PROCESS ON *.* TO 'testy'@'localhost' |
+---------------------------------------------+

是的,您可以创建一个没有 SUPER 权限的特殊用户来查看进程列表。