17.2.4.2 Replication Metadata Repositories

A replica server creates two replication metadata repositories, the connection metadata repository and the applier metadata repository. The replication metadata repositories survive a replica server's shutdown. If binary log file position based replication is in use, when the replica restarts, it reads the two repositories to determine how far it previously proceeded in reading the binary log from the source and in processing its own relay log. If GTID-based replication is in use, the replica does not use the replication metadata repositories for that purpose, but does need them for the other metadata that they contain.

The connection metadata repository is written to the slave_master_info table in the mysql system schema, and the applier metadata repository is written to the slave_relay_log_info table in the mysql system schema. A warning message is issued if mysqld is unable to initialize the tables for the replication metadata repositories, but the replica is allowed to continue starting. This situation is most likely to occur when upgrading from a version of MySQL that does not support the use of tables for the repositories to one in which they are supported.

Important重要
  1. Do not attempt to update or insert rows in the mysql.slave_master_info or mysql.slave_relay_log_info tables manually. Doing so can cause undefined behavior, and is not supported. Execution of any statement requiring a write lock on either or both of the slave_master_info and slave_relay_log_info tables is disallowed while replication is ongoing (although statements that perform only reads are permitted at any time).

  2. Access privileges for the connection metadata repository table mysql.slave_master_info should be restricted to the database administrator, because it contains the replication user account name and password for connecting to the source. Use a restricted access mode to protect database backups that include this table. From MySQL 8.0.21, you can clear the replication user account credentials from the connection metadata repository, and instead always provide them using the START REPLICA | SLAVE statement or START GROUP_REPLICATION statement that starts the replication channel. This approach means that the replication channel always needs operator intervention to restart, but the account name and password are not recorded in the replication metadata repositories.

RESET REPLICA | SLAVE clears the data in the replication metadata repositories, with the exception of the replication connection parameters (depending on the MySQL Server release). For details, see the description for RESET REPLICA | SLAVE.

Before MySQL 8.0, to create the replication metadata repositories as tables, it was necessary to specify master_info_repository=TABLE and relay_log_info_repository=TABLE at server startup. Otherwise, the repositories were created as files in the data directory named master.info and relay-log.info, or with alternative names and locations specified by the --master-info-file option and relay_log_info_file system variable. From MySQL 8.0, creating the replication metadata repositories as tables is the default, and the use of all these system variables is deprecated.

The mysql.slave_master_info and mysql.slave_relay_log_info tables are created using the InnoDB transactional storage engine. Updates to the applier metadata repository table are committed together with the transactions, meaning that the replica's progress information recorded in that repository is always consistent with what has been applied to the database, even in the event of an unexpected server halt. For information on the combination of settings on a replica that is most resilient to unexpected halts, see Section 17.4.2, “Handling an Unexpected Halt of a Replica”.

When you back up the replica's data or transfer a snapshot of its data to create a new replica, ensure that you include the mysql.slave_master_info and mysql.slave_relay_log_info tables containing the replication metadata repositories. For cloning operations, note that when the replication metadata repositories are created as tables, they are copied to the recipient during a cloning operation, but when they are created as files, they are not copied. When binary log file position based replication is in use, the replication metadata repositories are needed to resume replication after restarting the restored, copied, or cloned replica. If you do not have the relay log files, but still have the applier metadata repository, you can check it to determine how far the replication SQL thread has executed in the source's binary log. Then you can use a CHANGE REPLICATION SOURCE TO statement (from MySQL 8.0.23) or CHANGE MASTER TO statement (before MySQL 8.0.23) with the SOURCE_LOG_FILE | MASTER_LOG_FILE and SOURCE_LOG_POS | MASTER_LOG_POS options to tell the replica to re-read the binary logs from the source from that point (provided that the required binary logs still exist on the source).

One additional repository, the applier worker metadata repository, is created primarily for internal use, and holds status information about worker threads on a multithreaded replica. The applier worker metadata repository includes the names and positions for the relay log file and the source's binary log file for each worker thread. If the applier metadata repository is created as a table, which is the default, the applier worker metadata repository is written to the mysql.slave_worker_info table. If the applier metadata repository is written to a file, the applier worker metadata repository is written to the worker-relay-log.info file. For external use, status information for worker threads is presented in the Performance Schema replication_applier_status_by_worker table.

The replication metadata repositories originally contained information similar to that shown in the output of the SHOW REPLICA | SLAVE STATUS statement, which is discussed in Section 13.4.2, “SQL Statements for Controlling Replica Servers”. Further information has since been added to the replication metadata repositories which is not displayed by the SHOW REPLICA | SLAVE STATUS statement.

For the connection metadata repository, the following table shows the correspondence between the columns in the mysql.slave_master_info table, the columns displayed by SHOW REPLICA | SLAVE STATUS, and the lines in the deprecated master.info file.

slave_master_info Table ColumnSHOW REPLICA | SLAVE STATUS Columnmaster.info File LineDescription
Number_of_lines[None]1Number of columns in the table (or lines in the file)
Master_log_nameSource_Log_File2The name of the binary log currently being read from the source
Master_log_posRead_Source_Log_Pos3The current position within the binary log that has been read from the source
HostSource_Host4The host name of the replication source server
User_nameSource_User5The replication user account name used to connect to the source
User_passwordPassword (not shown by SHOW REPLICA | SLAVE STATUS)6The replication user account password used to connect to the source
PortSource_Port7The network port used to connect to the replication source server
Connect_retryConnect_Retry8The period (in seconds) that the replica waits before trying to reconnect to the source
Enabled_sslSource_SSL_Allowed9Whether the replica supports SSL connections
Ssl_caSource_SSL_CA_File10The file used for the Certificate Authority (CA) certificate
Ssl_capathSource_SSL_CA_Path11The path to the Certificate Authority (CA) certificate
Ssl_certSource_SSL_Cert12The name of the SSL certificate file
Ssl_cipherSource_SSL_Cipher13The list of possible ciphers used in the handshake for the SSL connection
Ssl_keySource_SSL_Key14The name of the SSL key file
Ssl_verify_server_certSource_SSL_Verify_Server_Cert15Whether to verify the server certificate
Heartbeat[None]16Interval between replication heartbeats, in seconds
BindSource_Bind17Which of the replica's network interfaces should be used for connecting to the source
Ignored_server_idsReplicate_Ignore_Server_Ids18The list of server IDs to be ignored. Note that for Ignored_server_ids the list of server IDs is preceded by the total number of server IDs to ignore.
UuidSource_UUID19The source's unique ID
Retry_countSource_Retry_Count20Maximum number of reconnection attempts permitted
Ssl_crl[None]21Path to an SSL certificate revocation-list file
Ssl_crlpath[None]22Path to a directory containing SSL certificate revocation-list files
Enabled_auto_positionAuto_position23Whether GTID auto-positioning is in use or not
Channel_nameChannel_name24The name of the replication channel
Tls_versionSource_TLS_Version25TLS version on the source
Public_key_pathSource_public_key_path26Name of the RSA public key file
Get_public_keyGet_source_public_key27Whether to request RSA public key from source
Network_namespaceNetwork_namespace28Network namespace
Master_compression_algorithm[None]29Permitted compression algorithms for the connection to the source
Master_zstd_compression_level[None]30zstd compression level
Tls_ciphersuites[None]31Permitted ciphersuites for TLSv1.3
Source_connection_auto_failover[None]32Whether the asynchronous connection failover mechanism is activated

For the applier metadata repository, the following table shows the correspondence between the columns in the mysql.slave_relay_log_info table, the columns displayed by SHOW REPLICA | SLAVE STATUS, and the lines in the deprecated relay-log.info file.

slave_relay_log_info Table ColumnSHOW REPLICA | SLAVE STATUS ColumnLine in relay-log.info FileDescription
Number_of_lines[None]1Number of columns in the table or lines in the file
Relay_log_nameRelay_Log_File2The name of the current relay log file
Relay_log_posRelay_Log_Pos3The current position within the relay log file; events up to this position have been executed on the replica database
Master_log_nameRelay_Source_Log_File4The name of the source's binary log file from which the events in the relay log file were read
Master_log_posExec_Source_Log_Pos5The equivalent position within the source's binary log file of the events that have been executed on the replica
Sql_delaySQL_Delay6The number of seconds that the replica must lag the source
Number_of_workers[None]7The number of worker threads for applying replication transactions in parallel
Id[None]8ID used for internal purposes; currently this is always 1
Channel_nameChannel_name9The name of the replication channel
Privilege_checks_username[None]10The user name for the PRIVILEGE_CHECKS_USER account for the channel
Privilege_checks_hostname[None]11The host name for the PRIVILEGE_CHECKS_USER account for the channel
Require_row_format[None]12Whether the channel accepts only row-based events
Require_table_primary_key_check[None]13The channel's policy on whether tables must have primary keys for CREATE TABLE and ALTER TABLE operations
Assign_gtids_to_anonymous_transactions_type [None]14Whether the channel assigns a GTID to replicated transactions that do not already have one, and if so, whether it uses the replica's local UUID or a manually set UUID
Assign_gtids_to_anonymous_transactions_value [None]15The UUID used in the GTIDs assigned to anonymous transactions