## 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)
- 檢查線程信息