DBAtlas · Database operations atlas

Rebuild a replica from scratch with the CLONE plugin

MySQLReplication

Command

-- Donor (healthy replica or source)
INSTALL PLUGIN clone SONAME 'mysql_clone.so';
CREATE USER 'clone_donor'@'%' IDENTIFIED BY 'Cl0ne#Donor';
GRANT BACKUP_ADMIN ON *.* TO 'clone_donor'@'%';

-- Recipient (replica to rebuild; its data is replaced)
INSTALL PLUGIN clone SONAME 'mysql_clone.so';
SET GLOBAL clone_valid_donor_list = 'db1:3306';
CLONE INSTANCE FROM 'clone_donor'@'db1':3306 IDENTIFIED BY 'Cl0ne#Donor';

-- After the restart: verify and start replication
SELECT STATE, ERROR_NO, BINLOG_FILE, BINLOG_POSITION, GTID_EXECUTED FROM performance_schema.clone_status;
SELECT STAGE, STATE, ROUND(DATA / 1024 / 1024) AS data_mb FROM performance_schema.clone_progress;
CHANGE REPLICATION SOURCE TO SOURCE_HOST = 'db1', SOURCE_PORT = 3306, SOURCE_USER = 'repl', SOURCE_PASSWORD = 'Repl#2024', SOURCE_AUTO_POSITION = 1, SOURCE_SSL = 1;
START REPLICA;

What it does

Physically copies the donor's InnoDB data over the network, restarts the recipient and carries over the GTID state; produces a consistent replica without separate backup, transfer and restore steps.

When to use it

To rebuild a corrupted replica, one with errant GTIDs or one so far behind that its binlogs were purged, or to add a new replica.

Caution

All data on the recipient (users included) is replaced by the donor's copy; the root password becomes the donor's. Donor and recipient need the same release series, platform and plugin set (before 8.0.37 the exact same point release was required). The recipient user running the command needs CLONE_ADMIN. When the clone finishes mysqld restarts itself; without a supervisor such as systemd / mysqld_safe it returns 3707 'Restart server failed (mysqld is not managed by supervisor process)'. That is not a failure: the clone is complete, start the server manually. The donor sees heavy IO / network load; cap it with clone_max_concurrency and clone_max_data_bandwidth. With GTID off, use BINLOG_FILE / BINLOG_POSITION from clone_status as SOURCE_LOG_FILE / SOURCE_LOG_POS.

Open in DBAtlas →

Related