1

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

SHOW PROCESSLIST;

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

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

我不希望 root 用户使用这个简单的查询!

有什么解决办法吗?

4

1 回答 1

1

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

如果您有 PROCESS 权限,您可以查看所有线程,甚至是属于其他用户的线程。否则(没有 PROCESS 特权),非匿名用户可以访问有关他们自己的线程的信息,但不能访问其他用户的线程,并且匿名用户无权访问线程信息。

让我们测试创建一个用户并只授予他们 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 权限的特殊用户,该用户可以查看进程列表。

于 2021-10-11T05:10:33.980 回答