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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

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

29.12.8 性能模式连接表29.12.8 Performance Schema Connection Tables

当客户端连接到 MySQL 服务器时,它是以特定的用户名和来自特定主机进行连接的。性能模式提供了关于这些连接的统计信息,按账户(用户名和主机组合)进行跟踪,也可以分别按用户名和主机名进行跟踪,使用以下表:When a client connects to the MySQL server, it does so under a particular user name and from a particular host. The Performance Schema provides statistics about these connections, tracking them per account (user and host combination) as well as separately per user name and host name, using these tables:

  • accounts:每个客户端账户的连接统计信息accounts: Connection statistics per client account

  • hosts:每个客户端主机名的连接统计信息hosts: Connection statistics per client host name

  • users:每个客户端用户名的连接统计信息users: Connection statistics per client user name

在连接表中,“account” 的含义与 mysql 系统数据库中的 MySQL 授权表含义类似,即该术语指的是用户和主机值的组合。不同之处在于,对于授权表,账户的主机部分可以是一个模式,而对于 Performance Schema 表,主机值总是一个特定的非模式主机名。The meaning of “account” in the connection tables is similar to its meaning in the MySQL grant tables in the mysql system database, in the sense that the term refers to a combination of user and host values. They differ in that, for grant tables, the host part of an account can be a pattern, whereas for Performance Schema tables, the host value is always a specific nonpattern host name.

每个连接表都有 CURRENT_CONNECTIONS 和 TOTAL_CONNECTIONS 列,用于跟踪每个 “跟踪值” 的当前连接数和总连接数。各表使用的跟踪值不同。accounts 表有 USER 和 HOST 列,用于跟踪每个用户和主机组合的连接。users 表和 hosts 表分别有 USER 和 HOST 列,用于跟踪每个用户名和主机名的连接数。Each connection table has CURRENT_CONNECTIONS and TOTAL_CONNECTIONS columns to track the current and total number of connections per “tracking value” on which its statistics are based. The tables differ in what they use for the tracking value. The accounts table has USER and HOST columns to track connections per user and host combination. The users and hosts tables have a USER and HOST column, respectively, to track connections per user name and host name.

性能模式还会统计内部线程以及未能通过认证的用户会话线程,使用USER和HOST列值为NULL的行。The Performance Schema also counts internal threads and threads for user sessions that failed to authenticate, using rows with USER and HOST column values of NULL.

假设名为user1和user2的客户端分别从hosta和hostb各连接一次。性能模式会如下跟踪这些连接:Suppose that clients named user1 and user2 each connect one time from hosta and hostb. The Performance Schema tracks the connections as follows:

  • accounts 表有四行,分别对应 user1/hosta、user1/hostb、user2/hosta 和 user2/hostb 的账户值,每行计算每个账户的一次连接。The accounts table has four rows, for the user1/hosta, user1/hostb, user2/hosta, and user2/hostb account values, each row counting one connection per account.

  • hosts 表有两行,分别对应 hosta 和 hostb,每行计算每个主机名的两次连接。The hosts table has two rows, for hosta and hostb, each row counting two connections per host name.

  • users 表有两行,分别对应 user1 和 user2,每行计算每个用户名的两个连接数。The users table has two rows, for user1 and user2, each row counting two connections per user name.

当客户端连接时,性能模式会使用每个表相应的跟踪值确定每个连接表中的哪一行适用。如果没有这样的行,则会添加一行。然后性能模式会将该行中的 CURRENT_CONNECTIONS 和 TOTAL_CONNECTIONS 列的值都增加一。When a client connects, the Performance Schema determines which row in each connection table applies, using the tracking value appropriate to each table. If there is no such row, one is added. Then the Performance Schema increments by one the CURRENT_CONNECTIONS and TOTAL_CONNECTIONS columns in that row.

当客户端断开连接时,性能模式会将该行中的 CURRENT_CONNECTIONS 列的值减一,而 TOTAL_CONNECTIONS 列保持不变。When a client disconnects, the Performance Schema decrements by one the CURRENT_CONNECTIONS column in the row and leaves the TOTAL_CONNECTIONS column unchanged.

TRUNCATE TABLE 允许用于连接表。它具有以下效果:TRUNCATE TABLE is permitted for connection tables. It has these effects:

  • 对于没有当前连接的账户、主机或用户,会移除对应的行(CURRENT_CONNECTIONS = 0 的行)。Rows are removed for accounts, hosts, or users that have no current connections (rows with CURRENT_CONNECTIONS = 0).

  • 未被移除的行将重置为只计算当前连接数:对于 CURRENT_CONNECTIONS > 0 的行,TOTAL_CONNECTIONS 会被重置为 CURRENT_CONNECTIONS。Nonremoved rows are reset to count only current connections: For rows with CURRENT_CONNECTIONS > 0, TOTAL_CONNECTIONS is reset to CURRENT_CONNECTIONS.

  • 依赖于连接表的汇总表会被隐式截断,如本节后面所述。Summary tables that depend on the connection table are implicitly truncated, as described later in this section.

性能模式维护汇总表,这些表按账户、主机或用户汇总各种事件类型的连接统计信息。这些表的名称中包含_summary_by_account、_summary_by_host或_summary_by_user。要识别它们,请使用以下查询:The Performance Schema maintains summary tables that aggregate connection statistics for various event types by account, host, or user. These tables have _summary_by_account, _summary_by_host, or _summary_by_user in the name. To identify them, use this query:

mysql> SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
       WHERE TABLE_SCHEMA = 'performance_schema'
       AND TABLE_NAME REGEXP '_summary_by_(account|host|user)'
       ORDER BY TABLE_NAME;
+------------------------------------------------------+
| TABLE_NAME                                           |
+------------------------------------------------------+
| events_errors_summary_by_account_by_error            |
| events_errors_summary_by_host_by_error               |
| events_errors_summary_by_user_by_error               |
| events_stages_summary_by_account_by_event_name       |
| events_stages_summary_by_host_by_event_name          |
| events_stages_summary_by_user_by_event_name          |
| events_statements_summary_by_account_by_event_name   |
| events_statements_summary_by_host_by_event_name      |
| events_statements_summary_by_user_by_event_name      |
| events_transactions_summary_by_account_by_event_name |
| events_transactions_summary_by_host_by_event_name    |
| events_transactions_summary_by_user_by_event_name    |
| events_waits_summary_by_account_by_event_name        |
| events_waits_summary_by_host_by_event_name           |
| events_waits_summary_by_user_by_event_name           |
| memory_summary_by_account_by_event_name              |
| memory_summary_by_host_by_event_name                 |
| memory_summary_by_user_by_event_name                 |
+------------------------------------------------------+

有关各个连接汇总表的详细信息,请查阅描述汇总事件类型的表的部分:For details about individual connection summary tables, consult the section that describes tables for the summarized event type:

TRUNCATE TABLE 允许用于连接汇总表。它会删除没有连接的帐户、主机或用户的行,并将剩余行的汇总列重置为零。此外,每个按帐户、主机、用户或线程汇总的汇总表,都会因为其依赖的连接表被截断而被隐式截断。下表描述了连接表截断与隐式截断表之间的关系。TRUNCATE TABLE is permitted for connection summary tables. It removes rows for accounts, hosts, or users with no connections, and resets the summary columns to zero for the remaining rows. In addition, each summary table that is aggregated by account, host, user, or thread is implicitly truncated by truncation of the connection table on which it depends. The following table describes the relationship between connection table truncation and implicitly truncated tables.

表 29.2 连接表截断的隐式影响Table 29.2 Implicit Effects of Connection Table Truncation

被截断的连接表Truncated Connection Table 隐式截断的汇总表Implicitly Truncated Summary Tables
accounts 表名中包含 _summary_by_account、_summary_by_thread 的表Tables with names containing _summary_by_account, _summary_by_thread
hosts 表名包含 _summary_by_account、_summary_by_host、_summary_by_thread 的表Tables with names containing _summary_by_account, _summary_by_host, _summary_by_thread
users 表名包含 _summary_by_account、_summary_by_user、_summary_by_thread 的表Tables with names containing _summary_by_account, _summary_by_user, _summary_by_thread

截断 _summary_global 汇总表也会隐式截断其对应的连接和线程汇总表。例如,截断 events_waits_summary_global_by_event_name 会隐式截断按账户、主机、用户或线程汇总的等待事件汇总表。Truncating a _summary_global summary table also implicitly truncates its corresponding connection and thread summary tables. For example, truncating events_waits_summary_global_by_event_name implicitly truncates the wait event summary tables that are aggregated by account, host, user, or thread.