Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 37.2Mb
PDF (A4) - 37.2Mb
PDF (RPM) - 36.9Mb
EPUB - 10.5Mb
HTML Download (TGZ) - 10.3Mb
HTML Download (Zip) - 10.3Mb
HTML Download (RPM) - 8.9Mb
Eclipse Doc Plugin (TGZ) - 11.1Mb
Eclipse Doc Plugin (Zip) - 13.3Mb
Man Pages (TGZ) - 203.8Kb
Man Pages (Zip) - 309.1Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
Excerpts from this Manual

MySQL 5.7 Reference Manual  /  ...  /  Multi-Source Replication Tutorials

18.1.4.2 Multi-Source Replication Tutorials

This section provides tutorials on how to configure masters and slaves for multi-source replication, and how to start, stop and reset multi-source slaves.

18.1.4.2.1 Configuring Multi-Source Replication

This section explains how to configure a multi-source replication topology, and provides details about configuring masters and slaves. Such a topology requires at least two masters and one slave configured.

Masters in a multi-source replication topology can be configured to use either global transaction identifier (GTID) based replication, or binary log position-based replication. See Section 18.1.3.2, “Setting Up Replication Using GTIDs” for how to configure a master using GTID based replication. See Section 18.1.2.1, “Setting the Replication Master Configuration” for how to configure a master using file position based replication.

Slaves in a multi-source replication topology require TABLE based repositories. Multi-source replication is not compatible with FILE based repositories. The type of repository being used by mysqld can be configured either at startup, or dynamically.

To configure the type of repository used by a replication slave at startup, start mysqld with the following options:

--master-info-repository=TABLE --relay-log-info-repository=TABLE

To modify an existing replication slave that is using a FILE repository to use TABLE repositories, convert the existing replication repositories dynamically by running the following commands:

STOP SLAVE;
SET GLOBAL master_info_repository = 'TABLE';
SET GLOBAL relay_log_info_repository = 'TABLE';
18.1.4.2.2 Adding a GTID Based Master to a Multi-Source Replication Slave

This section assumes you have enabled GTID based transactions on the master using gtid_mode=ON, enabled a replication user, and ensured that the slave is using TABLE based replication repositories. Use the CHANGE MASTER TO statement to add a new master to a channel by using a FOR CHANNEL channel clause. For more information on replication channels, see Section 18.2.3, “Replication Channels”

For example, to add a new master with the host name master1 using port 3451 to a channel called master-1:


CHANGE MASTER TO MASTER_HOST='master1', MASTER_USER='rpl', MASTER_PORT=3451, MASTER_PASSWORD='', \
MASTER_AUTO_POSITION = 1 FOR CHANNEL 'master-1';

Multi-source replication is compatible with auto-positioning. See Section 14.4.2.1, “CHANGE MASTER TO Syntax” for more information.

Repeat this process for each extra master that you want to add to a channel, changing the host name, port and channel as appropriate.

18.1.4.2.3 Adding a Binary Log Based Master to a Multi-Source Replication Slave

This section assumes you have enabled binary logging on the master using --log-bin, enabled a replication user, noted the current binary log position, and ensured that the slave is using TABLE based replication repositories. You need to know the current MASTER_LOG_FILE and MASTER_LOG_POSITION. Use the CHANGE MASTER TO statement to add a new master to a channel by specifying a FOR CHANNEL channel clause. For example, to add a new master with the host name master1 using port 3451 to a channel called master-1:


CHANGE MASTER TO MASTER_HOST='master1', MASTER_USER='rpl', MASTER_PORT=3451, MASTER_PASSWORD='' \
MASTER_LOG_FILE='master1-bin.000006', MASTER_LOG_POS=628 FOR CHANNEL 'master-1';

Repeat this process for each extra master that you want to add to a channel, changing the host name, port and channel as appropriate.

18.1.4.2.4 Starting Multi-Source Replication Slaves

Once you have added all of the channels you want to use as replication masters, use a START SLAVE thread_types statement to start replication. When you have enabled multiple channels on a slave, you can choose to either start all channels, or select a specific channel to start.

  • To start all currently configured replication channels:

     
    START SLAVE thread_types;
  • To start only a named channel, use a FOR CHANNEL channel clause:

     
    START SLAVE thread_types FOR CHANNEL channel;
    

Use the thread_types option to choose specific threads you want the above statements to start on the slave. See Section 14.4.2.6, “START SLAVE Syntax” for more information.

18.1.4.2.5 Stopping Multi-Source Replication Slaves

The STOP SLAVE statement can be used to stop a multi-source replication slave. By default, if you use the STOP SLAVE statement on a multi-source replication slave all channels are stopped. Optionally, use the FOR CHANNEL channel clause to stop only a specific channel.

  • To stop all currently configured replication channels:

    
    STOP SLAVE thread_types;
  • To stop only a named channel, use a FOR CHANNEL channel clause:

     
    STOP SLAVE thread_types FOR CHANNEL channel;
    

Use the thread_types option to choose specific threads you want the above statements to stop on the slave. See Section 14.4.2.7, “STOP SLAVE Syntax” for more information.

18.1.4.2.6 Resetting Multi-Source Replication Slaves

The RESET SLAVE statement can be used to reset a multi-source replication slave. By default, if you use the RESET SLAVE statement on a multi-source replication slave all channels are reset. Optionally, use the FOR CHANNEL channel clause to reset only a specific channel.

  • To reset all currently configured replication channels:

     
    RESET SLAVE;
  • To reset only a named channel, use a FOR CHANNEL channel clause:

     
    RESET SLAVE FOR CHANNEL channel;
    

See Section 14.4.2.4, “RESET SLAVE Syntax” for more information.


User Comments
Sign Up Login You must be logged in to post a comment.