## 8.14 检查线程信息
When you are attempting to ascertain what your MySQL server is doing, it can be helpful to examine the process list, which is the set of threads currently executing within the server. 进程列表信息可以从以下来源中获得:
- `SHOW [FULL] PROCESSLIST` 语句: [Section 13.7.6.29, “SHOW PROCESSLIST 语法](https://dev.mysql.com/doc/refman/8.0/en/show-processlist.html)
- [`SHOW PROFILE`](https://dev.mysql.com/doc/refman/8.0/en/show-profile.html) 语句: [Section 13.7.6.31, “SHOW PROFILES 语法](https://dev.mysql.com/doc/refman/8.0/en/show-profiles.html)
- `INFORMATION_SCHEMA` [`PROCESSLIST`](https://dev.mysql.com/doc/refman/8.0/en/processlist-table.html) 表: [Section 25.19, “The INFORMATION_SCHEMA PROCESSLIST Table”](https://dev.mysql.com/doc/refman/8.0/en/processlist-table.html)
- The [**mysqladmin processlist**](https://dev.mysql.com/doc/refman/8.0/en/mysqladmin.html) 命令: [Section 4.5.2, “**mysqladmin** — 管理 MySQL 服务器的客户端”](https://dev.mysql.com/doc/refman/8.0/en/mysqladmin.html)
- The Performance Schema [`threads`](https://dev.mysql.com/doc/refman/8.0/en/threads-table.html) table, stage tables, and lock tables: [Section 26.12.17, “Performance Schema Miscellaneous Tables”](https://dev.mysql.com/doc/refman/8.0/en/performance-schema-miscellaneous-tables.html), [Section 26.12.5, “Performance Schema Stage Event Tables”](https://dev.mysql.com/doc/refman/8.0/en/performance-schema-stage-tables.html), [Section 26.12.12, “Performance Schema Lock Tables”](https://dev.mysql.com/doc/refman/8.0/en/performance-schema-lock-tables.html).
Access to [`threads`](https://dev.mysql.com/doc/refman/8.0/en/threads-table.html) does not require a mutex and has minimal impact on server performance. [`INFORMATION_SCHEMA.PROCESSLIST`](https://dev.mysql.com/doc/refman/8.0/en/processlist-table.html) and [`SHOW PROCESSLIST`](https://dev.mysql.com/doc/refman/8.0/en/show-processlist.html) have negative performance consequences because they require a mutex. [`threads`](https://dev.mysql.com/doc/refman/8.0/en/threads-table.html) also shows information about background threads, which [`INFORMATION_SCHEMA.PROCESSLIST`](https://dev.mysql.com/doc/refman/8.0/en/processlist-table.html) and [`SHOW PROCESSLIST`](https://dev.mysql.com/doc/refman/8.0/en/show-processlist.html) do not. This means that [`threads`](https://dev.mysql.com/doc/refman/8.0/en/threads-table.html) can be used to monitor activity the other thread information sources cannot.
You can always view information about your own threads. To view information about threads being executed for other accounts, you must have the [`PROCESS`](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_process) privilege.
Each process list entry contains several pieces of information:
- `Id` 是线程关联的客户端的连接标识符.
- `User` 和 `Host` 表示与线程关联的账户.
- `db` 是线程默认的数据库, 如果没有选择, 则为 NULL.
- `Command` 和 `State` 表示线程正在做什么.
大多数状态对应非常快速的操作, 如果一个线程在给定的状态中停留了许多秒, 那么可能需要研究一下这个问题.
- `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`](https://dev.mysql.com/doc/refman/8.0/en/set-variable.html). For a thread running on a slave that is processing events from the master, the thread time is set to the time found in the events and thus reflects current time on the master and not the slave.
- `Info` contains the text of the statement being executed by the thread, or NULL if it is not executing one. By default, this value contains only the first 100 characters of the statement. To see the complete statements, use [`SHOW FULL PROCESSLIST`](https://dev.mysql.com/doc/refman/8.0/en/show-processlist.html).
- The `sys` schema [processlist](https://dev.mysql.com/doc/refman/8.0/en/sys-processlist.html) view, which presents information from the Performance Schema [`threads`](https://dev.mysql.com/doc/refman/8.0/en/threads-table.html) table in a more accessible format: [Section 27.4.3.22, “The processlist and x$processlist Views”](https://dev.mysql.com/doc/refman/8.0/en/sys-processlist.html)
- The `sys` schema [`session`](https://dev.mysql.com/doc/refman/8.0/en/sys-session.html) view, which presents information about user sessions (like the `sys` schema [`processlist`](https://dev.mysql.com/doc/refman/8.0/en/sys-processlist.html) view, but with background processes filtered out): [Section 27.4.3.33, “The session and x$session Views”(https://dev.mysql.com/doc/refman/8.0/en/sys-session.html)]
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.
- 简介
- 前言和法律条款
- 安装和更新 MySQL
- 在 Linux 上安装 MySQL
- 在 Linux 上使用 APT 库安装 MySQL
- 在 Linux 上使用 Docker 部署 MySQL
- 使用 Docker 部署 MySQL 服务器的基本步骤
- 使用 Docker 部署 MySQL 服务器的更多主题
- 教程
- 连接到服务器和从服务器断开
- 输入查询
- 创建和使用数据库
- 创建和选择数据库
- 创建表
- 将数据加载到表中
- 从表中检索数据
- 选择所有数据
- 选择特定行
- 选择指定列
- 行排序
- 日期计算
- 处理 NULL 值
- 模式匹配
- 计算行数
- 使用多个表
- 获取数据库和表的信息
- 在批处理模式使用 mysql
- 常见查询示例
- 列的最大值
- 包含某一行最大值的记录
- 每组中列的最大值
- 拥有某个字段的组间最大值的行
- 使用用户自定义变量
- 使用外键
- 两个键上搜索
- 计算每日访问量
- 使用 AUTO_INCREMENT
- 在 Apache 中使用 MySQL
- MySQL 程序
- MySQL 客户端程序
- mysql — MySQL 命令行客户端
- 优化
- 优化概述
- 优化 SQL 语句
- 优化和索引
- 优化数据库结构
- 优化 InnoDB 表
- 优化 MyISAM 表
- 优化 MEMORY 表
- 理解查询执行计划
- 控制查询优化器
- 缓冲和缓存
- 优化锁操作
- 优化 MySQL 服务器
- 测量性能 (Benchmarking)
- 检查线程信息