As of MySQL 5.6.6, application programs can provide key/value
pairs as connection attributes to be passed to the server at at
connect time. For the C API, define the attribute set using the
mysql_options() and
mysql_options4() functions.
Other MySQL Connectors may provide their own
attribute-definition methods.
These tables expose attribute information:
session_account_connect_attrs:
Connection attributes for the current session, and other
sessions associated with the session account
session_connect_attrs:
Connection attributes for all sessions
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.
The set of connection attributes visible on a given connection varies depending on your platform and MySQL Connector used to establish the connection.
The libmysqlclient client library (provided
in MySQL and MySQL Connector/C distributions) sets these attributes:
_client_name: The client name
(libmysql for the client library)
_client_version: The client library
version
_os: The operating system (for example,
Linux, Win64)
_pid: The client process ID
_platform: The machine platform (for
example, x86_64)
_thread: The client thread ID (Windows
only)
Other MySQL Connectors may define their own connection attributes.
MySQL Connector/J defines these attributes:
_client_license: The connector license
type
_runtime_vendor: The Java runtime
environment (JRE) vendor
_runtime_version: The Java runtime
environment (JRE) version
MySQL Connector/Net defines these attributes:
_client_version: The client library
version
_os: The operating system (for example,
Linux, Win64)
_pid: The client process ID
_platform: The machine platform (for
example, x86_64)
_program_name: The client name
_thread: The client thread ID (Windows
only)
PHP defines attributes that depend on how it was compiled:
Compiled using libmysqlclient: The
standard libmysqlclient attributes,
described previously
Compiled using mysqlnd: Only the
_client_name attribute, with a value of
mysqlnd
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.
Some MySQL clients define additional attributes:
mysqlbinlog defines the
_client_role attribute as
binary_log_listener.
Replication slave connections define
program_name as mysqld
and _client_role as
binary_log_listener.
FEDERATED storage engine
connections define program_name as
mysqld and
_client_role as
federated_storage.
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; and a configurable limit imposed by the Performance Schema at connect time.
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:
The server imposes a limit of 64KB on the aggregate size of connection attribute data it will accept. If a client attempts to send more than 64KB of attribute data, the server rejects the connection.
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:
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.
The Performance Schema writes a message to the error log
if the log_warnings
system variable is greater than zero:
[Warning] Connection attributes of length N were truncated