Documentation Home
MySQL Replication
Related Documentation Download this Excerpt
PDF (US Ltr) - 1.4Mb
PDF (A4) - 1.4Mb


5.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 replica'sconnection metadata repository contains information that the replication I/O thread needs to connect to the replication source server and retrieve transactions from the source's binary log. The metadata in this repository includes the connection configuration, the replication user account details, the SSL settings for the connection, and the file name and position where the replication I/O thread is currently reading from the source's binary log.

  • The replica'sapplier metadata repository contains information that the replication SQL thread needs to read and apply transactions from the replica's relay log. The metadata in this repository includes the file name and position up to which the replication SQL thread has executed the transactions in the relay log, and the equivalent position in the source's binary log. It also includes metadata for the process of applying transactions, such as the number of worker threads.

By default, the replication metadata repositories are created as files in the data directory namedmaster.info andrelay-log.info, or with alternative names and locations specified by the--master-info-file option andrelay_log_info_file system variable. To create the replication metadata repositories as tables, specifymaster_info_repository=TABLE andrelay_log_info_repository=TABLE at server startup. In that case, the replica's connection metadata repository is written to theslave_master_info table in themysql system schema, and the replica's applier metadata repository is written to theslave_relay_log_info table in themysql system schema. A warning message is issued ifmysqld 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 themysql.slave_master_info ormysql.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 theslave_master_info andslave_relay_log_info tables is disallowed while replication is ongoing (although statements that perform only reads are permitted at any time).

  2. Access to the replica's connection metadata repository file or table 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 repository.

RESET SLAVE clears the data in the replication metadata repositories, with the exception of the replication connection parameters (depending on the MySQL Server release and repository type). For details, see the description forRESET SLAVE.

If you setmaster_info_repository andrelay_log_info_repository toTABLE, themysql.slave_master_info andmysql.slave_relay_log_info tables are created using theInnoDB transactional storage engine. Updates to the replica's 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. The--relay-log-recovery option must be enabled on the replica to guarantee resilience. For more details, seeSection 3.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 themysql.slave_master_info andmysql.slave_relay_log_info tables containing the replication metadata repositories, or the equivalent files (master.info andrelay-log.info in the data directory, unless you specified alternative names and locations). When binary log file position based replication is in use, the replication metadata repositories are needed to resume replication after restarting the restored or copied replica. If you do not have the relay log files, but still have the replica's 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 aCHANGE MASTER TO statement with theMASTER_LOG_FILE andMASTER_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 replica's applier metadata repository is created as a table, which is the default, the applier worker metadata repository is written to themysql.slave_worker_info table. If the applier metadata repository is written to a file, the applier worker metadata repository is written to theworker-relay-log.info file. For external use, status information for worker threads is presented in the Performance Schemareplication_applier_status_by_worker table.

The replication metadata repositories originally contained information similar to that shown in the output of theSHOW SLAVE STATUS statement, which is discussed inSQL Statements for Controlling Replica Servers. Further information has since been added to the replication metadata repositories which is not displayed by theSHOW SLAVE STATUS statement.

For the connection metadata repository, the following table shows the correspondence between the columns in themysql.slave_master_info table, the columns displayed bySHOW SLAVE STATUS, and the lines in themaster.info file.

master.info File Lineslave_master_info Table ColumnSHOW SLAVE STATUS ColumnDescription
1Number_of_lines[None]Number of lines in the file, or columns in the table
2Master_log_nameMaster_Log_FileThe name of the binary log currently being read from the source
3Master_log_posRead_Master_Log_PosThe current position within the binary log that has been read from the source
4HostMaster_HostThe host name of the source server
5User_nameMaster_UserThe replication user name used to connect to the source
6User_passwordPassword (not shown bySHOW SLAVE STATUS)The password used to connect to the source
7PortMaster_PortThe network port used to connect to the source
8Connect_retryConnect_RetryThe period (in seconds) that the replica waits before trying to reconnect to the source
9Enabled_sslMaster_SSL_AllowedIndicates whether the server supports SSL connections
10Ssl_caMaster_SSL_CA_FileThe file used for the Certificate Authority (CA) certificate
11Ssl_capathMaster_SSL_CA_PathThe path to the Certificate Authority (CA) certificates
12Ssl_certMaster_SSL_CertThe name of the SSL certificate file
13Ssl_cipherMaster_SSL_CipherThe list of possible ciphers used in the handshake for the SSL connection
14Ssl_keyMaster_SSL_KeyThe name of the SSL key file
15Ssl_verify_server_certMaster_SSL_Verify_Server_CertWhether to verify the server certificate
16Heartbeat[None]Interval between replication heartbeats, in seconds
17BindMaster_BindWhich of the replica's network interfaces should be used for connecting to the source
18Ignored_server_idsReplicate_Ignore_Server_IdsThe list of server IDs to be ignored. Note that forIgnored_server_ids the list of server IDs is preceded by the total number of server IDs to ignore.
19UuidMaster_UUIDThe source's unique ID
20Retry_countMaster_Retry_CountMaximum number of reconnection attempts permitted
21Ssl_crl[None]Path to an SSL certificate revocation-list file
22Ssl_crlpath[None]Path to a directory containing SSL certificate revocation-list files
23Enabled_auto_positionAuto_positionIf autopositioning is in use or not
24Channel_nameChannel_nameThe name of the replication channel
25Tls_versionMaster_TLS_VersionTLS version on source

For the applier metadata repository, the following table shows the correspondence between the columns in themysql.slave_relay_log_info table, the columns displayed bySHOW SLAVE STATUS, and the lines in therelay-log.info file.

Line inrelay-log.infoslave_relay_log_info Table ColumnSHOW SLAVE STATUS ColumnDescription
1Number_of_lines[None]Number of lines in the file or columns in the table
2Relay_log_nameRelay_Log_FileThe name of the current relay log file
3Relay_log_posRelay_Log_PosThe current position within the relay log file; events up to this position have been executed on the replica database
4Master_log_nameRelay_Master_Log_FileThe name of the source's binary log file from which the events in the relay log file were read
5Master_log_posExec_Master_Log_PosThe equivalent position within the source's binary log file of events that have already been executed
6Sql_delaySQL_DelayThe number of seconds that the replica must lag the source
7Number_of_workers[None]The number of worker threads on the replica for executing replication events (transactions) in parallel
8Id[None]ID used for internal purposes; currently this is always 1
9Channel_nameChannel_nameThe name of the replication channel

In versions of MySQL prior to MySQL 5.6, therelay-log.info file does not include a line count or a delay value (and theslave_relay_log_info table is not available).

LineStatus ColumnDescription
1Relay_Log_FileThe name of the current relay log file
2Relay_Log_PosThe current position within the relay log file; events up to this position have been executed on the replica database
3Relay_Master_Log_FileThe name of the source's binary log file from which the events in the relay log file were read
4Exec_Master_Log_PosThe equivalent position within the source's binary log file of events that have already been executed
Note

If you downgrade a replica server to a version older than MySQL 5.6, the older server does not read therelay-log.info file correctly. To address this, modify the file in a text editor by deleting the initial line containing the number of lines.

The contents of therelay-log.info file and the states shown by theSHOW SLAVE STATUS statement might not match if therelay-log.info file has not been flushed to disk. Ideally, you should only viewrelay-log.info on a replica that is offline (that is,mysqld is not running). For a running system, you can useSHOW SLAVE STATUS, or query themysql.slave_master_info andmysql.slave_relay_log_info tables if you are writing the replication metadata repositories to tables.