简体   繁体   中英

Creating a new MySQL replica from an existing replica

I'm using a standard MySQL replica setup with a single master and a single replica. Now I want to create a new replica so that I have one master and two replicas. To setup the new replica, I wanted to do a MySQL dump of the existing replica instead of doing this from the master.

When doing this, I think I first need to stop the replica to get a consistent dataset:

mysql> STOP SLAVE;

Then I would find the replication coordinates so I can start my new replica at the correct replication point:

mysql> SHOW SLAVE STATUS\G

Then I would take the dump by running this command on the replica:

bash> mysqldump --single-transaction --quick --lock-tables=false --insert-ignore --all-databases --master-data=2 | gzip > data-for-replica.sql.gz

and after the MySQL dump is complete, I would restart the replica to let it catch back up:

mysql> START SLAVE; 

My question is: since I'm using --single-transaction when doing my dump, can I parallelize these tasks:

  1. Stop replication, check coordinates, and then initiate the MySQL dump
  2. Re-start the replica in a separate shell while the dump is taking place

Would anything go wrong? Would I get inconsistent data and coordinates that would prevent me from creating the new replica in a sane state?

My hope would be to avoid having to wait for the dump to finish for a large database before restarting the replica that the backup is taken from. Since the dump is happening in a single transaction, any updates from the master would not be included in the dump, and hence the dump would be consistent with the coordinates I checked while the replica was stopped. Am I missing anything?

mysqldump is a read only action, not a transaction. So if mysqldump dumps only non-committed data, and your transaction stays open for the duration of the dump, the import in the new slave and the activation of the new slave, then theoretically you could do this. In practice however I think this scenario is unlikely to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM