在MySQL中如何給普通使用者授予檢視所有使用者線程/連接配接的權限,當然,預設情況下show processlist是可以檢視目前使用者的線程/連接配接的。
mysql> grant process on MyDB.* to test;
ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES
第一次授予這樣的權限,錯誤原因是process權限是一個全局權限,不可以指定在某一個庫上(個人測試庫為MyDB),是以,把授權語句更改為如下即可:
mysql> grant process on *.* to test;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
如果不給擁有授予PROESS權限 ,show processlist指令隻能看到目前使用者的線程,而授予了PROCESS權限後,使用show processlist就能看到所有使用者的線程。官方文檔的介紹如下:
SHOW PROCESSLIST shows you which threads are running. You can also get this information from the INFORMATION_SCHEMA PROCESSLIST table or the mysqladmin processlist command. If you have the PROCESS privilege, you can see all threads. Otherwise, you can see only your own threads (that is, threads associated with the MySQL account that you are using). If you do not use the FULL keyword, only the first 100 characters of each statement are shown in the Info field.
我們先建立下面賬号test2,然後測試如下:

然後我們給使用者test2授予process權限, 如下所示,再測試show processlist 就能看到所有使用者的線程/連接配接資訊(如果是之前已經建立連接配接的會話,必須退出重新登入,否則依然隻能看到目前使用者的線程。)
mysql> grant process on *.* to test2;
Query OK, 0 rows affected (0.00 sec)
The PROCESS privilege pertains to display of information about the threads executing within the server (that is, information about the statements being executed by sessions). The privilege enables use of SHOW PROCESSLIST or <b>mysqladmin processlist</b> to see threads belonging to other accounts; you can always see your own threads. The PROCESS privilege also enables use of SHOW ENGINE.
如上官方文檔所說,如果給使用者授予了PROCESS權限, 那麼使用者就擁有了使用SHOW ENGINES指令的權限,如下所示: