## MySQL Multi-Source Replication 

cat dumpM2.sql | grep GTID_PURGED | perl -p0 -e ’s#/\*.*?\*/##sg’ | cut -f2 -d’=’ | cut -f2 -d$’\’’ 

The result in each case should be a GTID set, for example: 

source1: 2174B383-5441-11E8-B90A-C80AA9429562:1-1029 source2: 224DA167-0C0C-11E8-8442-00059A3C7B00:1-2695 

3. Remove the line from each dump file that contains the SET @@GLOBAL.gtid_purged  statement. For example: 

sed ’/GTID_PURGED/d’ dumpM1.sql > dumpM1_nopurge.sql sed ’/GTID_PURGED/d’ dumpM2.sql > dumpM2_nopurge.sql 

4. Use the mysql  client to import each edited dump file into the replica. For example: 

mysql -u< user > -p< password > < dumpM1_nopurge.sql mysql -u< user > -p< password > < dumpM2_nopurge.sql 

5. On the replica, issue RESET MASTER  to clear the GTID execution history (assuming, as explained above, that all the dump files have been imported and that there are no wanted transactions with GTIDs on the replica). Then issue a SET @@GLOBAL.gtid_purged  statement to set the gtid_purged  value to the union of all the GTID sets from all the dump files, as you recorded in Step 2. For example: 

mysql> RESET MASTER; mysql> SET 

If there are, or might be, overlapping transactions between the GTID sets in the dump files, you can use the stored functions described in Section 17.1.3.8, “Stored Function Examples to Manipulate GTIDs”  to check this beforehand and to calculate the union of all the GTID sets. 

## 17.1.5.3 Adding GTID-Based Sources to a Multi-Source Replica 

These steps assume you have enabled GTIDs for transactions on the sources using gtid_mode=ON , created a replication user, ensured that the replica is using TABLE  based replication applier metadata repositories, and provisioned the replica with data from the sources if appropriate. 

Use the CHANGE REPLICATION SOURCE TO  statement (from MySQL 8.0.23) or CHANGE MASTER TO  statement (before MySQL 8.0.23) to configure a replication channel for each source on the replica (see Section 17.2.2, “Replication Channels” ). The FOR CHANNEL  clause is used to specify the channel. For GTID-based replication, GTID auto-positioning is used to synchronize with the source (see Section 17.1.3.3, “GTID Auto-Positioning” ). The SOURCE_AUTO_POSITION  | MASTER_AUTO_POSITION option is set to specify the use of auto-positioning. 

For example, to add source1  and source2  as sources to the replica, use the mysql  client to issue the statement twice on the replica, like this: 

mysql> CHANGE MASTER TO MASTER_HOST="source1", MASTER_USER="ted", \ MASTER_PASSWORD=" password ", MASTER_AUTO_POSITION=1 FOR CHANNEL "source_1"; mysql> CHANGE MASTER TO MASTER_HOST="source2", MASTER_USER="ted", \ MASTER_PASSWORD=" password ", MASTER_AUTO_POSITION=1 FOR CHANNEL "source_2"; Or from MySQL 8.0.23: mysql> CHANGE REPLICATION SOURCE TO SOURCE_HOST="source1", SOURCE_USER="ted", \ SOURCE_PASSWORD=" password ", SOURCE_AUTO_POSITION=1 FOR CHANNEL "source_1"; mysql> CHANGE REPLICATION SOURCE TO SOURCE_HOST="source2", SOURCE_USER="ted", \ SOURCE_PASSWORD=" password ", SOURCE_AUTO_POSITION=1 FOR CHANNEL "source_2"; 

To make the replica replicate only database db1  from source1 , and only database db2  from source2 , use the mysql  client to issue the CHANGE REPLICATION FILTER  statement for each channel, like this: 

