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_ 状态变量的统计信息。要获取全局和每个会话的语句执行次数,分别使用 xxxevents_statements_summary_global_by_event_name 和 events_statements_summary_by_thread_by_event_name 表。例如:The Performance Schema does not collect statistics for
Com_ status
variables in the status variable tables. To obtain global and
per-session statement execution counts, use the
xxxevents_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. Forglobal_status, this column contains the global value. Forsession_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 theTHREAD_IDcolumn.
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:
global_status:重置线程、账户、主机和用户状态。重置全局状态变量,除了服务器从不重置的那些。global_status: Resets thread, account, host, and user status. Resets global status variables except those that the server never resets.session_status:不支持。session_status: Not supported.status_by_thread:将所有线程的状态汇总到全局状态和账户状态,然后重置线程状态。如果未收集账户统计信息,则会将会话状态添加到主机和用户状态中(如果收集了主机和用户状态)。status_by_thread: Aggregates status for all threads to the global status and account status, then resets thread status. If account statistics are not collected, the session status is added to host and user status, if host and user status are collected.如果相应的
performance_schema_accounts_size、performance_schema_hosts_size和performance_schema_users_size系统变量被设置为 0,则不会收集账户、主机和用户统计信息。Account, host, and user statistics are not collected if theperformance_schema_accounts_size,performance_schema_hosts_size, andperformance_schema_users_sizesystem variables, respectively, are set to 0.
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.