列出已登录的 MySQL 用户?
要列出已登录的 MySQL 用户,可以使用以下两种方法 −
方法一
使用 INFORMATION_SCHEMA.PROCESSLIST
select *from INFORMATION_SCHEMA.PROCESSLIST;
方法二
还可以使用 SHOW PROCESSLIST 命令。以下是语法 −
SHOW PROCESSLIST;
让我们实现上述语法,以便列出已登录的 MySQL 用户 −
mysql> select *from information_schema.processlist;
这将产生以下输出 -
+----+-----------------+-----------------+------+---------+--------+-----------------------------+---------------------------------------------+ | ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO | +----+-----------------+-----------------+------+---------+--------+-----------------------------+---------------------------------------------+ | 8 | root | localhost:50252 | web | Query | 0 | executing | select *from information_schema.processlist | | 4 | event_scheduler | localhost | NULL | Daemon | 301832 | Waiting for next activation | NULL | +----+-----------------+-----------------+------+---------+--------+-----------------------------+---------------------------------------------+ 2 rows in set (0.00 sec)
现在,让我们看看第二个查询 −
mysql> show processlist;
这将产生以下输出 -
+----+-----------------+-----------------+------+---------+--------+-----------------------------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+-----------------+-----------------+------+---------+--------+-----------------------------+------------------+ | 4 | event_scheduler | localhost | NULL | Daemon | 301842 | Waiting for next activation | NULL | | 8 | root | localhost:50252 | web | Query | 1 | starting | show processlist | +----+-----------------+-----------------+------+---------+--------+-----------------------------+------------------+ 2 rows in set (0.19 sec)
广告