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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

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

29.12.9 性能模式连接属性表29.12.9 Performance Schema Connection Attribute Tables

连接属性是应用程序在连接时可以传递给服务器的键值对。对于基于由 libmysqlclient 客户端库实现的 C API 的应用程序,mysql_options() 和 mysql_options4() 函数定义了连接属性集。其他 MySQL 连接器可能提供它们自己的属性定义方法。Connection attributes are key-value pairs that application programs can pass to the server at connect time. For applications based on the C API implemented by the libmysqlclient client library, the mysql_options() and mysql_options4() functions define the connection attribute set. Other MySQL Connectors may provide their own attribute-definition methods.

这些性能模式表公开属性信息:These Performance Schema tables expose attribute information:

此外,写入审计日志的连接事件可能包括连接属性。参见 第 8.4.5.4 节,“审计日志文件格式”。In addition, connect events written to the audit log may include connection attributes. See Section 8.4.5.4, “Audit Log File Formats”.

以下划线(_)开头的属性名称保留用于内部使用,应用程序不应创建这些属性。此约定允许 MySQL 引入新属性而不会与应用程序属性冲突,并使应用程序能够定义不会与内部属性冲突的自定义属性。Attribute names that begin with an underscore (_) are reserved for internal use and should not be created by application programs. This convention permits new attributes to be introduced by MySQL without colliding with application attributes, and enables application programs to define their own attributes that do not collide with internal attributes.

可用连接属性Available Connection Attributes

在给定连接中可见的连接属性集合会因平台、用于建立连接的 MySQL 连接器或客户端程序等因素而有所不同。The set of connection attributes visible within a given connection varies depending on factors such as your platform, MySQL Connector used to establish the connection, or client program.

libmysqlclient 客户端库设置这些属性:The libmysqlclient client library sets these attributes:

  • _client_name:客户端名称(客户端库为 libmysql)。_client_name: The client name (libmysql for the client library).

  • _client_version:客户端库版本。_client_version: The client library version.

  • _os:操作系统(例如 Linux、Win64)。_os: The operating system (for example, Linux, Win64).

  • _pid:客户端进程 ID。_pid: The client process ID.

  • _platform:机器平台(例如 x86_64)。_platform: The machine platform (for example, x86_64).

  • _thread:客户端线程 ID(仅限 Windows)。_thread: The client thread ID (Windows only).

其他 MySQL 连接器可能会定义它们自己的连接属性。Other MySQL Connectors may define their own connection attributes.

MySQL Connector/C 为使用 X DevAPI 或 X DevAPI for C 的应用程序定义了这些属性:MySQL Connector/C++ defines these attributes for applications that use X DevAPI or X DevAPI for C:

  • _client_license:连接器许可(例如 GPL-2.0)。_client_license: The connector license (for example GPL-2.0).

  • _client_name:连接器名称(mysql-connector-cpp)。_client_name: The connector name (mysql-connector-cpp).

  • _client_version:连接器版本。_client_version: The connector version.

  • _os:操作系统(例如 Linux、Win64)。_os: The operating system (for example, Linux, Win64).

  • _pid:客户端进程 ID。_pid: The client process ID.

  • _platform:机器平台(例如 x86_64)。_platform: The machine platform (for example, x86_64).

  • _source_host:客户端运行所在机器的主机名。_source_host: The host name of the machine on which the client is running.

  • _thread:客户端线程 ID(仅限 Windows)。_thread: The client thread ID (Windows only).

MySQL Connector/J 定义了这些属性: MySQL Connector/J defines these attributes:

  • _client_name:客户端名称_client_name: The client name

  • _client_version:客户端库版本_client_version: The client library version

  • _os:操作系统(例如,Linux,Win64)_os: The operating system (for example, Linux, Win64)

  • _client_license:连接器许可证类型_client_license: The connector license type

  • _platform:机器平台(例如,x86_64)_platform: The machine platform (for example, x86_64)

  • _runtime_vendor:Java 运行环境(JRE)供应商_runtime_vendor: The Java runtime environment (JRE) vendor

  • _runtime_version:Java 运行环境(JRE)版本_runtime_version: The Java runtime environment (JRE) version

MySQL Connector/NET 定义了这些属性:MySQL Connector/NET defines these attributes:

  • _client_version:客户端库版本。_client_version: The client library version.

  • _os:操作系统(例如 Linux、Win64)。_os: The operating system (for example, Linux, Win64).

  • _pid:客户端进程 ID。_pid: The client process ID.

  • _platform:机器平台(例如 x86_64)。_platform: The machine platform (for example, x86_64).

  • _program_name:客户端名称。_program_name: The client name.

  • _thread:客户端线程 ID(仅限 Windows)。_thread: The client thread ID (Windows only).

Connector/Python 实现定义了这些属性;某些值和属性取决于 Connector/Python 的实现(纯 Python 或 C 扩展):The Connector/Python implementation defines these attributes; some values and attributes depend on the Connector/Python implementation (pure python or c-ext):

  • _client_license:连接器的许可证类型;GPL-2.0 或 Commercial。(仅限纯 Python)_client_license: The license type of the connector; GPL-2.0 or Commercial. (pure python only)

  • _client_name:设置为 mysql-connector-python(纯 Python)或 libmysql(C 扩展)_client_name: Set to mysql-connector-python (pure python) or libmysql (c-ext)

  • _client_version:连接器版本(纯 Python)或 mysqlclient 库版本(C 扩展)。_client_version: The connector version (pure python) or mysqlclient library version (c-ext).

  • _os:连接器所在操作系统(例如,Linux、Win64)。_os: The operating system with the connector (for example, Linux, Win64).

  • _pid:源机器上的进程标识符(例如,26955)_pid: The process identifier on the source machine (for example, 26955)

  • _platform:机器平台(例如 x86_64)。_platform: The machine platform (for example, x86_64).

  • _source_host:连接器来源机器的主机名。_source_host: The host name of the machine on which the connector is connecting from.

  • _connector_version:连接器版本(例如,8.4.9)(仅限 c-ext)。_connector_version: The connector version (for example, 8.4.9) (c-ext only).

  • _connector_license:连接器的许可证类型;GPL-2.0 或 Commercial(仅限 c-ext)。_connector_license: The license type of the connector; GPL-2.0 or Commercial (c-ext only).

  • _connector_name:始终设置为 mysql-connector-python(仅限 c-ext)。_connector_name: Always set to mysql-connector-python (c-ext only).

PHP 定义的属性取决于其编译方式:PHP defines attributes that depend on how it was compiled:

  • 使用 libmysqlclient 编译:标准的 libmysqlclient 属性,如前所述。Compiled using libmysqlclient: The standard libmysqlclient attributes, described previously.

  • 使用 mysqlnd 编译:仅有 _client_name 属性,值为 mysqlnd。Compiled using mysqlnd: Only the _client_name attribute, with a value of mysqlnd.

许多 MySQL 客户端程序会设置一个 program_name 属性,其值等于客户端名称。例如,mysqladmin 和 mysqldump 分别将 program_name 设置为 mysqladmin 和 mysqldump。MySQL Shell 将 program_name 设置为 mysqlsh。Many MySQL client programs set a program_name attribute with a value equal to the client name. For example, mysqladmin and mysqldump set program_name to mysqladmin and mysqldump, respectively. MySQL Shell sets program_name to mysqlsh.

一些 MySQL 客户端程序定义了额外的属性:Some MySQL client programs define additional attributes:

  • mysql:mysql:

    • os_user:运行程序的操作系统用户名。适用于 Unix 及类 Unix 系统和 Windows。os_user: The name of the operating system user running the program. Available on Unix and Unix-like systems and Windows.

    • os_sudouser:SUDO_USER 环境变量的值。适用于 Unix 及类 Unix 系统。os_sudouser: The value of the SUDO_USER environment variable. Available on Unix and Unix-like systems.

    mysql 连接属性值为空的不会发送。mysql connection attributes for which the value is empty are not sent.

  • mysqlbinlog:mysqlbinlog:

    • _client_role: binary_log_listener

  • 副本连接:Replica connections:

    • program_name: mysqld

    • _client_role: binary_log_listener

    • _client_replication_channel_name:通道名称。_client_replication_channel_name: The channel name.

  • FEDERATED 存储引擎连接:FEDERATED storage engine connections:

    • program_name: mysqld

    • _client_role: federated_storage

连接属性限制Connection Attribute Limits

从客户端传输到服务器的连接属性数据有以下限制:There are limits on the amount of connection attribute data transmitted from client to server:

  • 客户端在连接前施加的固定限制。A fixed limit imposed by the client prior to connect time.

  • 服务器在连接时施加的固定限制。A fixed limit imposed by the server at connect time.

  • Performance Schema 在连接时施加的可配置限制。A configurable limit imposed by the Performance Schema at connect time.

对于使用 C API 发起的连接,libmysqlclient 库对客户端连接属性数据的总大小施加了 64KB 的限制:调用 mysql_options() 如果导致超出此限制,会产生 CR_INVALID_PARAMETER_NO 错误。其他 MySQL 连接器可能会对向服务器传输的连接属性数据量施加自己的客户端限制。For connections initiated using the C API, the libmysqlclient library imposes a limit of 64KB on the aggregate size of connection attribute data on the client side: Calls to mysql_options() that cause this limit to be exceeded produce a CR_INVALID_PARAMETER_NO error. Other MySQL Connectors may impose their own client-side limits on how much connection attribute data can be transmitted to the server.

在服务器端,会在以下情况下对连接属性数据进行大小检查:On the server side, these size checks on connection attribute data occur:

  • 服务器对其接受的连接属性数据的总大小施加了 64KB 的限制。如果客户端尝试发送超过 64KB 的属性数据,服务器将拒绝连接。否则,服务器会认为属性缓冲区有效,并在Performance_schema_session_connect_attrs_longest_seen状态变量中记录最长此类缓冲区的大小。The server imposes a limit of 64KB on the aggregate size of connection attribute data it accepts. If a client attempts to send more than 64KB of attribute data, the server rejects the connection. Otherwise, the server considers the attribute buffer valid and tracks the size of the longest such buffer in the Performance_schema_session_connect_attrs_longest_seen status variable.

  • 对于被接受的连接,Performance Schema 会将属性总大小与performance_schema_session_connect_attrs_size系统变量的值进行比较。如果属性大小超过该值,将执行以下操作:For accepted connections, the Performance Schema checks aggregate attribute size against the value of the performance_schema_session_connect_attrs_size system variable. If attribute size exceeds this value, these actions take place:

    • 性能模式会截断属性数据,并增加 Performance_schema_session_connect_attrs_lost 状态变量,该变量表示发生属性截断的连接数量。The Performance Schema truncates the attribute data and increments the Performance_schema_session_connect_attrs_lost status variable, which indicates the number of connections for which attribute truncation occurred.

    • 如果 log_error_verbosity 系统变量大于 1,性能模式会将一条消息写入错误日志:The Performance Schema writes a message to the error log if the log_error_verbosity system variable is greater than 1:

      Connection attributes of length N were truncated
      (N bytes lost)
      for connection N, user user_name@host_name
      (as user_name), auth: {yes|no}
      

      警告消息中的信息旨在帮助数据库管理员识别发生属性截断的客户端。The information in the warning message is intended to help DBAs identify clients for which attribute truncation occurred.

    • 如果属性缓冲区有足够的空间,一个 _truncated 属性会被添加到会话属性中,其值表示丢失了多少字节。这允许性能模式在连接属性表中显示每个连接的截断信息。可以在不检查错误日志的情况下查看这些信息。A _truncated attribute is added to the session attributes with a value indicating how many bytes were lost, if the attribute buffer has sufficient space. This enables the Performance Schema to expose per-connection truncation information in the connection attribute tables. This information can be examined without having to check the error log.