How to Use MySQL Clone Plugin to Provision Replica
This article provides a step-by-step guide on how to use the MySQL clone plugin to provision a new replica instance. You will learn how to install the clone plugin on both the donor and recipient servers, configure the necessary user privileges, and execute the clone command to automatically set up and synchronize a new MySQL replica.
The MySQL clone plugin, introduced in MySQL 8.0.17, allows you to clone data directly from a donor MySQL server instance to a recipient instance. This method is highly efficient as it bypasses the need for manual backup and restore tools like mysqldump or Enterprise Backup.
Step 1: Install the Clone Plugin
To use the cloning feature, you must load the clone plugin on both the donor (source) and recipient (target) MySQL instances. Run the following command on both servers:
INSTALL PLUGIN clone SONAME 'mysql_clone.so';You can verify the installation by checking the active plugins:
SHOW PLUGINS;Step 2: Create and Configure Administrative Users
The clone process requires specific administrative privileges on both instances.
On the Donor Instance, create a user and grant the
BACKUP_ADMIN privilege:
CREATE USER 'donor_user'@'%' IDENTIFIED BY 'password';
GRANT BACKUP_ADMIN ON *.* TO 'donor_user'@'%';On the Recipient Instance, create a user and grant
the CLONE_ADMIN privilege (this privilege automatically
includes BACKUP_ADMIN and allows the recipient to write the
cloned data):
CREATE USER 'recipient_user'@'localhost' IDENTIFIED BY 'password';
GRANT CLONE_ADMIN ON *.* TO 'recipient_user'@'localhost';Step 3: Configure the Valid Donor List
Before executing the clone operation, you must define which donor hosts the recipient is allowed to clone data from. Execute the following command on the Recipient Instance to register the donor’s IP address and MySQL port:
SET GLOBAL clone_valid_donor_list = 'donor_host_ip:3306';Step 4: Execute the Clone Command
Log in to the Recipient Instance as the recipient
user created in Step 2. Run the CLONE INSTANCE command to
begin transferring data:
CLONE INSTANCE FROM 'donor_user'@'donor_host_ip':3306 IDENTIFIED BY 'password';During this process, the recipient instance will: 1. Connect to the donor. 2. Transfer the data files, replacing the existing data on the recipient. 3. Automatically restart to apply the cloned data.
Step 5: Start Replication
Because the clone plugin copies the data directory exactly, it also copies the GTID coordinates and binary log positions from the donor.
To start replication after the recipient server automatically restarts, configure the replica to point to the source and start the replication threads:
CHANGE REPLICATION SOURCE TO
SOURCE_HOST='donor_host_ip',
SOURCE_USER='replication_user',
SOURCE_PASSWORD='replication_password',
SOURCE_AUTO_POSITION=1;
START REPLICA;Ensure the replication user exists on the source database. You can
monitor the status of the replica using
SHOW REPLICA STATUS\G.