列出已登录的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)

以上是 列出已登录的MySQL用户? 的全部内容, 来源链接: utcz.com/z/345605.html

回到顶部