以下讨论列举了进程信息的来源、查看进程信息所需的权限,并描述了进程列表条目的内容。The following discussion enumerates the sources of process information, the privileges required to see process information, and describes the content of process list entries.
可以从以下来源获取过程信息:Process information is available from these sources:
SHOW PROCESSLIST语句:第 15.7.7.31 节,“SHOW PROCESSLIST 语句”TheSHOW PROCESSLISTstatement: Section 15.7.7.31, “SHOW PROCESSLIST Statement”mysqladmin processlist 命令:第 6.5.2 节,“mysqladmin — MySQL 服务器管理程序”The mysqladmin processlist command: Section 6.5.2, “mysqladmin — A MySQL Server Administration Program”
INFORMATION_SCHEMAPROCESSLIST表: 第 28.3.23 节,“INFORMATION_SCHEMA PROCESSLIST 表”TheINFORMATION_SCHEMAPROCESSLISTtable: Section 28.3.23, “The INFORMATION_SCHEMA PROCESSLIST Table”Performance Schema
processlist表: 第 29.12.22.7 节,“processlist 表”The Performance Schemaprocesslisttable: Section 29.12.22.7, “The processlist Table”Performance Schema
threads表中列名以PROCESSLIST_为前缀:第 29.12.22.8 节,“线程表”The Performance Schemathreadstable columns with names having a prefix ofPROCESSLIST_: Section 29.12.22.8, “The threads Table”sys模式的processlist和session视图:第 30.4.3.22 节,“进程列表和 x$processlist 视图”,以及 第 30.4.3.33 节,“会话和 x$session 视图”Thesysschemaprocesslistandsessionviews: Section 30.4.3.22, “The processlist and x$processlist Views”, and Section 30.4.3.33, “The session and x$session Views”
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 thethreadstable 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 forSHOW PROCESSLISTis available based on the Performance Schemaprocesslisttable, which, like thethreadstable, does not require a mutex and has better performance characteristics. For details, see Section 29.12.22.7, “The processlist Table”.threads表显示后台线程,这是其他源所没有的。它还为每个线程提供其他源没有的附加信息,例如线程是前台还是后台线程,以及线程在服务器中的位置。这意味着threads表可以用于监控其他源无法监控的线程活动。Thethreadstable 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 thethreadstable 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.
对于大多数进程信息来源,如果您具有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”.
每个进程列表条目包含几条信息。下列列表使用 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是与线程相关的客户端连接标识符。Idis the connection identifier for the client associated with the thread.User和Host表示与线程关联的账户。UserandHostindicate the account associated with the thread.db是线程的默认数据库,如果未选择任何数据库,则为NULL。dbis the default database for the thread, orNULLif none has been selected.Command和State表示线程正在执行的操作。CommandandStateindicate 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 possibleCommandvalues, andStatevalues 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 节,“复制线程”。Timeindicates 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 withSET TIMESTAMP =. 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”.valueInfo指示线程正在执行的语句,如果线程没有执行语句,则为NULL。对于SHOW PROCESSLIST,此值仅包含语句的前 100 个字符。要查看完整语句,请使用SHOW FULL PROCESSLIST(或查询其他进程信息来源)。Infoindicates the statement the thread is executing, orNULLif it is executing no statement. ForSHOW PROCESSLIST, this value contains only the first 100 characters of the statement. To see complete statements, useSHOW FULL PROCESSLIST(or query a different process information source).