Documentation Home

8.14.1 访问进程列表

下面的讨论列举了进程信息的来源、查看进程信息所需的权限,并描述了进程列表条目的内容。

过程信息来源

过程信息可从以下来源获得:

threads表与 SHOW PROCESSLISTINFORMATION_SCHEMA PROCESSLISTmysqladmin processlist的比较如下:

  • 访问该threads表不需要互斥锁,并且对服务器性能的影响最小。其他来源对性能有负面影响,因为它们需要互斥量。

    笔记

    SHOW PROCESSLIST从 MySQL 5.7.39 开始,基于 Performance Schema processlist表 的替代实现 是可用的,它与threads表一样,不需要互斥量并且具有更好的性能特征。有关详细信息,请参阅 第 25.12.16.3 节,“进程列表”

  • threads表显示了后台线程,而其他来源则没有。它还为每个线程提供其他来源不提供的附加信息,例如线程是前台线程还是后台线程,以及与线程关联的服务器内的位置。这意味着该 threads表可用于监视其他来源无法监视的线程活动。

  • 您可以启用或禁用 Performance Schema 线程监视,如 第 25.12.16.4 节,“线程表”中所述。

由于这些原因,使用其他线程信息源之一执行服务器监视的 DBA 可能希望改为使用该threads表进行监视。

sys架构 视图以更易于访问的格式processlist显示来自性能架构表的信息 。模式 视图显示有关用户会话的信息,如 threads模式视图 ,但过滤掉了后台进程。 syssessionsysprocesslist

访问进程列表所需的权限

For most sources of process information, 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.

The Performance Schema threads table also provides thread information, but table access uses a different privilege model. See Section 25.12.16.4, “The threads Table”.

Content of Process List Entries

每个进程列表条目包含几条信息。以下列表使用SHOW PROCESSLIST 输出中的标签描述了它们。其他过程信息源使用类似的标签。

  • Id是与线程关联的客户端的连接标识符。

  • UserHost 指明与线程关联的帐户。

  • db是线程的默认数据库,或者NULL如果未选择任何数据库。

  • CommandState 指出线程正在做什么。

    Most states correspond to very quick operations. If a thread stays in a given state for many seconds, there might be a problem that needs to be investigated.

    The following sections list the possible Command values, and State values grouped by category. The meaning for some of these values is self-evident. For others, additional description is provided.

    Note

    Applications that examine process list information should be aware that the commands and states are subject to change.

  • Time indicates how long the thread has been in its current state. The thread's notion of the current time may be altered in some cases: The thread can change the time with SET TIMESTAMP = value. For a replica SQL thread, the value is the number of seconds between the timestamp of the last replicated event and the real time of the replica host. See Section 16.2.3, “Replication Threads”.

  • Info指示线程正在执行的语句,或者NULL它是否正在执行任何语句。对于SHOW PROCESSLIST,此值仅包含语句的前 100 个字符。要查看完整的语句,请使用 SHOW FULL PROCESSLIST(或查询不同的过程信息源)。