8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

10.14.1 访问进程列表10.14.1 Accessing the Process List

以下讨论列举了进程信息的来源、查看进程信息所需的权限,并描述了进程列表条目的内容。The following discussion enumerates the sources of process information, the privileges required to see process information, and describes the content of process list entries.

进程信息来源Sources of Process Information

可以从以下来源获取过程信息:Process information is available from these sources:

threads 表与 SHOW PROCESSLIST、INFORMATION_SCHEMA PROCESSLIST 和 mysqladmin processlist 的比较如下:The threads table compares to SHOW PROCESSLIST, INFORMATION_SCHEMA PROCESSLIST, and mysqladmin processlist as follows:

  • 访问 threads 表不需要互斥锁,并且对服务器性能影响最小。其他来源会对性能产生负面影响,因为它们需要互斥锁。Access to the threads table does not require a mutex and has minimal impact on server performance. The other sources have negative performance consequences because they require a mutex.

    Note

    基于性能模式(Performance Schema)的 processlist 表,提供了 SHOW PROCESSLIST 的另一种实现方式。与 threads 表一样,该表不需要互斥锁,并且具有更好的性能特性。详情请参见 第 29.12.22.7 节,“Processlist 表”。An alternative implementation for SHOW PROCESSLIST is available based on the Performance Schema processlist table, which, like the threads table, does not require a mutex and has better performance characteristics. For details, see Section 29.12.22.7, “The processlist Table”.

  • threads 表显示后台线程,这是其他源所没有的。它还为每个线程提供其他源没有的附加信息,例如线程是前台还是后台线程,以及线程在服务器中的位置。这意味着 threads 表可以用于监控其他源无法监控的线程活动。The threads table displays background threads, which the other sources do not. It also provides additional information for each thread that the other sources do not, such as whether the thread is a foreground or background thread, and the location within the server associated with the thread. This means that the threads table can be used to monitor thread activity the other sources cannot.

  • 您可以按照 第 29.12.22.8 节,“threads 表” 中的描述启用或禁用性能模式线程监控。You can enable or disable Performance Schema thread monitoring, as described in Section 29.12.22.8, “The threads Table”.

出于这些原因,使用其他线程信息源进行服务器监控的数据库管理员可能希望改为使用 threads 表进行监控。For these reasons, DBAs who perform server monitoring using one of the other thread information sources may wish to monitor using the threads table instead.

sys 模式的 processlist 视图以更易访问的格式呈现来自 Performance Schema threads 表的信息。sys 模式的 session 视图呈现关于用户会话的信息,类似于 sys 模式的 processlist 视图,但会过滤掉后台进程。The sys schema processlist view presents information from the Performance Schema threads table in a more accessible format. The sys schema session view presents information about user sessions like the sys schema processlist view, but with background processes filtered out.

访问进程列表所需的权限Privileges Required to Access the Process List

对于大多数进程信息来源,如果您具有PROCESS权限,您可以查看所有线程,即使是属于其他用户的线程。否则(没有PROCESS权限),非匿名用户可以访问自己线程的信息,但无法访问其他用户的线程信息,匿名用户则无法访问任何线程信息。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.

Performance Schema 的threads表也提供线程信息,但表访问使用的是不同的权限模型。参见第 29.12.22.8 节,“threads 表”。The Performance Schema threads table also provides thread information, but table access uses a different privilege model. See Section 29.12.22.8, “The threads Table”.

进程列表条目的内容Content of Process List Entries

每个进程列表条目包含几条信息。下列列表使用 SHOW PROCESSLIST 输出中的标签对其进行描述。其他进程信息来源使用类似的标签。Each process list entry contains several pieces of information. The following list describes them using the labels from SHOW PROCESSLIST output. Other process information sources use similar labels.

  • Id 是与线程相关的客户端连接标识符。Id is the connection identifier for the client associated with the thread.

  • User 和 Host 表示与线程关联的账户。User and Host indicate the account associated with the thread.

  • db 是线程的默认数据库,如果未选择任何数据库,则为 NULL。db is the default database for the thread, or NULL if none has been selected.

  • Command 和 State 表示线程正在执行的操作。Command and State indicate what the thread is doing.

    大多数状态对应于非常快速的操作。如果一个线程在某个状态停留了好几秒,可能存在需要调查的问题。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.

    以下部分列出了可能的Command值,以及按类别分组的State值。其中一些值的含义是不言而喻的。对于其他值,则提供了额外的说明。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 表示线程处于当前状态的时间长度。线程对当前时间的认知在某些情况下可能会被修改:线程可以使用 SET TIMESTAMP = value 来更改时间。对于复制 SQL 线程,该值是最后一个已复制事件的时间戳与复制主机的实际时间之间的秒数。参见 第 19.2.3 节,“复制线程”。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 19.2.3, “Replication Threads”.

  • Info 指示线程正在执行的语句,如果线程没有执行语句,则为 NULL。对于 SHOW PROCESSLIST,此值仅包含语句的前 100 个字符。要查看完整语句,请使用 SHOW FULL PROCESSLIST(或查询其他进程信息来源)。Info indicates the statement the thread is executing, or NULL if it is executing no statement. For SHOW PROCESSLIST, this value contains only the first 100 characters of the statement. To see complete statements, use SHOW FULL PROCESSLIST (or query a different process information source).