A Guide to MySQL Clone Plugin: High-Speed Physical Data Cloning for Replica Scaling and Automatic Node Recovery

MySQL tutorial - IT technology blog
MySQL tutorial - IT technology blog

1. Quick Start: Setting up a remote replica in 5 minutes

Suppose you need to quickly spin up a Replica node from an active production Donor (MySQL 8.0). The traditional approach is running mysqldump, compressing files, and transferring them via scp. For a 500GB database, this workflow can easily take dozens of hours. The Clone Plugin completely eliminates these tedious steps, packaging the entire operation into just a few direct SQL statements.

Step 1: Install the Plugin on both Donor and Recipient

Open your terminal and connect to MySQL on both nodes (Donor: 192.168.1.10 and Recipient: 192.168.1.20):

INSTALL PLUGIN clone SONAME 'mysql_clone.so';
-- Check plugin status
SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME = 'clone';

If the result returns ACTIVE, the plugin is ready to use.

Step 2: Create a user and grant privileges on the Donor

The Donor node must grant the BACKUP_ADMIN privilege to allow the replica to pull a physical InnoDB snapshot:

CREATE USER 'clone_user'@'%' IDENTIFIED BY 'MatKhauSieuKho123!';
GRANT BACKUP_ADMIN ON *.* TO 'clone_user'@'%';
FLUSH PRIVILEGES;

Step 3: Configure and run the Clone command on the Recipient

On the Recipient node, create a local user with permissions to overwrite the data directory (CLONE_ADMIN). Next, add the Donor’s IP to the whitelist and initiate the clone process:

CREATE USER 'clone_local'@'localhost' IDENTIFIED BY 'MatKhauLocal123!';
GRANT CLONE_ADMIN ON *.* TO 'clone_local'@'localhost';

-- Log in as clone_local and execute:
SET GLOBAL clone_valid_donor_list = '192.168.1.10:3306';

CLONE INSTANCE FROM 'clone_user'@'192.168.1.10':3306 IDENTIFIED BY 'MatKhauSieuKho123!';

As soon as the command runs, the Recipient clears its existing data directory. All physical files from the Donor are streamed directly over the network socket. The mysqld daemon then restarts automatically. Once rebooted, the data is completely synchronized with the Donor.

2. Under the Hood: How does the Clone Plugin work?

Prior to MySQL 8.0.17, DBAs typically had only two options: using mysqldump or Percona XtraBackup. Logical dumps generate heavy CPU overhead and restoring hundreds of gigabytes is painfully slow. XtraBackup operates faster, but it requires complex shell scripts, manual file transfers, and OS-level permission management.

The Clone Plugin thoroughly addresses this challenge at the InnoDB storage engine layer through four sequential stages:

  • Drop Data: The Recipient purges the old data directory before accepting incoming data.
  • File Copy: The Donor streams tablespace files (.ibd) directly to the Recipient. During the copy process, the Donor continues processing INSERT, UPDATE, and DELETE operations as normal, without table-level locking.
  • Page Copy: Data pages modified during the file copy phase are buffered in memory and transmitted to the Recipient.
  • Redo Copy: All redo logs generated throughout the clone session are transferred to the Recipient. The target node then executes crash recovery to bring the data into a fully consistent snapshot state.

The Clone Plugin automatically captures the exact binary log coordinates or GTID positions at the snapshot checkpoint. You can start replication immediately without having to guess offsets or manually track down binlog positions.

3. Advanced: Automating Replication setup and Node Recovery

In production environments, pairing the Clone Plugin with GTID or InnoDB Cluster saves hours of manual work whenever you scale nodes.

Configuring Replication automatically after cloning

While waiting for the clone to finish, open another session on the Recipient to monitor progress:

SELECT STAGE, STATE, CURRENT_PAGE, TOTAL_PAGE, 
       ROUND(CURRENT_PAGE/TOTAL_PAGE*100, 2) AS '% Done'
FROM performance_schema.clone_progress;

Once the instance finishes restarting, verify that the GTID position has been synced automatically:

SELECT * FROM performance_schema.clone_status\G

The BINLOG_FILE, BINLOG_POSITION, and GTID_EXECUTED fields are all set. On clusters utilizing GTID, you only need to configure the replication channel without specifying manual coordinates:

CHANGE REPLICATION SOURCE TO 
  SOURCE_HOST = '192.168.1.10',
  SOURCE_PORT = 3306,
  SOURCE_USER = 'repl_user',
  SOURCE_PASSWORD = 'ReplPassword123!',
  SOURCE_AUTO_POSITION = 1;

START REPLICA;

Application in Group Replication and InnoDB Cluster

MySQL Group Replication relies on the Clone Plugin as the backbone for its Distributed Recovery mechanism. When a new node joins or an offline node has fallen behind so far that its required binlogs were purged, it automatically discovers an active donor. The physical clone process triggers automatically in the background, enabling self-healing cluster recovery without DevOps intervention.

4. Practical tips and common pitfalls

When our team first adopted this tool, we ran into an unforgettable incident. After running CLONE INSTANCE, the slave node suddenly dropped off the network and refused to come back online. It turned out the systemd service was missing an auto-restart directive. Here are three crucial caveats to keep in mind:

1. The node shuts down completely after cloning

The CLONE INSTANCE command actively stops and restarts mysqld on the Recipient. When running under systemd or Docker, the process supervisor must be configured to restart automatically. For systemd, ensure the service unit file includes Restart=always or Restart=on-failure. Otherwise, the server will simply shut down, forcing you to SSH in and start it manually.

2. Environmental mismatch between Donor and Recipient

Because this performs a block-level physical copy, both servers must have matching configurations:

  • MySQL Version: Both nodes must share the exact same minor release. Cloning from 8.0.32 to 8.0.35 will be outright rejected by MySQL.
  • OS and CPU Architecture: The operating system family and CPU architecture must match (e.g., x86_64 to x86_64; do not clone from an x86 Ubuntu machine to an ARM-based Apple Silicon host).
  • InnoDB Block Size: The innodb_page_size variable must be identical on both nodes (default is 16k).

3. Network bandwidth saturation on the Donor node

When cloning a 500GB database over a 1Gbps network, the Donor’s network interface can easily hit 100% saturation (~110MB/s–120MB/s). This can starve application traffic and trigger latency spikes. You should proactively throttle the clone bandwidth on the Donor:

-- Limit clone rate to 80MB/s to preserve bandwidth for application traffic
SET GLOBAL clone_max_data_bandwidth = 80;

Conversely, if you are running on a 10Gbps local network with high-end NVMe drives, increase the worker threads to shorten clone duration:

SET GLOBAL clone_max_concurrency = 16;

Mastering the MySQL Clone Plugin reduces the time needed to spin up a 1TB read replica to under 30–40 minutes, while making your system disaster recovery workflows vastly simpler.

Share: