文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

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

29.12.15 性能模式状态变量表29.12.15 Performance Schema Status Variable Tables

MySQL 服务器维护许多状态变量,这些变量提供其运行信息(见 第 7.1.10 节,“服务器状态变量”)。状态变量信息可在以下 Performance Schema 表中获得:The MySQL server maintains many status variables that provide information about its operation (see Section 7.1.10, “Server Status Variables”). Status variable information is available in these Performance Schema tables:

  • global_status:全局状态变量。只需要全局值的应用程序应使用此表。global_status: Global status variables. An application that wants only global values should use this table.

  • session_status: 当前会话的状态变量。希望获取自身会话所有状态变量值的应用程序应使用此表。它包括该会话的会话变量,以及没有会话对应的全局变量值。session_status: Status variables for the current session. An application that wants all status variable values for its own session should use this table. It includes the session variables for its session, as well as the values of global variables that have no session counterpart.

  • status_by_thread: 每个活动会话的会话状态变量。希望了解特定会话的会话变量值的应用程序应使用此表。它仅包括会话变量,通过线程 ID 进行标识。status_by_thread: Session status variables for each active session. An application that wants to know the session variable values for specific sessions should use this table. It includes session variables only, identified by thread ID.

还有一些汇总表提供按账户、主机名和用户名汇总的状态变量信息。请参见 第 29.12.20.12 节,“状态变量汇总表”。There are also summary tables that provide status variable information aggregated by account, host name, and user name. See Section 29.12.20.12, “Status Variable Summary Tables”.

会话变量表(session_status、status_by_thread)仅包含活动会话的信息,而不包含已终止会话的信息。The session variable tables (session_status, status_by_thread) contain information only for active sessions, not terminated sessions.

性能模式(Performance Schema)仅为在 threads 表中 INSTRUMENTED 值为 YES 的线程收集全局状态变量的统计信息。会话状态变量的统计信息始终会被收集,无论 INSTRUMENTED 值如何。The Performance Schema collects statistics for global status variables only for threads for which the INSTRUMENTED value is YES in the threads table. Statistics for session status variables are always collected, regardless of the INSTRUMENTED value.

性能模式不会收集状态变量表中 Com_xxx 状态变量的统计信息。要获取全局和每个会话的语句执行次数,分别使用 events_statements_summary_global_by_event_name 和 events_statements_summary_by_thread_by_event_name 表。例如:The Performance Schema does not collect statistics for Com_xxx status variables in the status variable tables. To obtain global and per-session statement execution counts, use the events_statements_summary_global_by_event_name and events_statements_summary_by_thread_by_event_name tables, respectively. For example:

SELECT EVENT_NAME, COUNT_STAR
FROM performance_schema.events_statements_summary_global_by_event_name
WHERE EVENT_NAME LIKE 'statement/sql/%';

global_status 和 session_status 表具有以下列:The global_status and session_status tables have these columns:

  • VARIABLE_NAME

    状态变量名称。The status variable name.

  • VARIABLE_VALUE

    状态变量的值。对于 global_status,此列包含全局值。对于 session_status,此列包含当前会话的变量值。The status variable value. For global_status, this column contains the global value. For session_status, this column contains the variable value for the current session.

global_status 和 session_status 表具有以下索引:The global_status and session_status tables have these indexes:

  • 主键在 (VARIABLE_NAME) 上Primary key on (VARIABLE_NAME)

status_by_thread 表包含每个活动线程的状态。它具有以下列:The status_by_thread table contains the status of each active thread. It has these columns:

  • THREAD_ID

    定义状态变量的会话的线程标识符。The thread identifier of the session in which the status variable is defined.

  • VARIABLE_NAME

    状态变量名称。The status variable name.

  • VARIABLE_VALUE

    由 THREAD_ID 列命名的会话的会话变量值。The session variable value for the session named by the THREAD_ID column.

status_by_thread 表具有以下索引:The status_by_thread table has these indexes:

  • 主键在 (THREAD_ID, VARIABLE_NAME) 上Primary key on (THREAD_ID, VARIABLE_NAME)

status_by_thread 表仅包含关于前台线程的状态变量信息。如果 performance_schema_max_thread_instances 系统变量未自动扩展(表示值为 −1)且允许的最大仪表化线程对象数量不大于后台线程的数量,则该表为空。The status_by_thread table contains status variable information only about foreground threads. If the performance_schema_max_thread_instances system variable is not autoscaled (signified by a value of −1) and the maximum permitted number of instrumented thread objects is not greater than the number of background threads, the table is empty.

Performance Schema 支持对状态变量表使用 TRUNCATE TABLE,具体如下:The Performance Schema supports TRUNCATE TABLE for status variable tables as follows:

FLUSH STATUS 会将所有活动会话的会话状态添加到全局状态变量中,重置所有活动会话的状态,并重置从已断开会话汇总的账户、主机和用户状态值。FLUSH STATUS adds the session status from all active sessions to the global status variables, resets the status of all active sessions, and resets account, host, and user status values aggregated from disconnected sessions.