Skip to main content

How to run mysql clone on a server

1. Prerequisites

Before you start, ensure both servers meet these requirements:

  • Version: Both must be MySQL 8.0.17 or higher.

  • Operating System: Must be the same (e.g., both Linux).

  • Plugins: The clone_plugin must be installed on both.

2. Step-by-Step Configuration

Phase A: Prepare the Donor (Primary)

Log into your Primary server and run:

SQL
-- Install the plugin
INSTALL PLUGIN clone SONAME 'mysql_clone.so';

-- Create a replication user with cloning permissions
CREATE USER 'clone_user'@'%' IDENTIFIED BY 'password';
GRANT BACKUP_ADMIN ON *.* TO 'clone_user'@'%';

Phase B: Prepare the Recipient (Replica)

Log into your New Replica server and run:

SQL
-- Install the plugin
INSTALL PLUGIN clone SONAME 'mysql_clone.so';

-- Allow the recipient to be overwritten by the donor
SET GLOBAL clone_valid_donor_list = 'primary-ip-address:3306';

Phase C: Execute the Clone

On the Recipient server, trigger the data transfer. Warning: This will delete all existing data on the recipient and restart the MySQL service automatically after completion.

SQL
CLONE INSTANCE FROM 'clone_user'@'primary-ip-address':3306 IDENTIFIED BY 'password';


3. Completing the Replication

The beauty of the Clone plugin is that it automatically captures the Binary Log coordinates (GTID or filename/position) during the transfer.

Once the recipient restarts, log back in and check the status:

SQL
SELECT BINLOG_FILE, BINLOG_POS FROM performance_schema.clone_status;

Option 1: If using GTIDs (Recommended)

If your primary uses GTIDs, replication might start automatically or simply require:

SQL
CHANGE REPLICATION SOURCE TO 
    SOURCE_HOST='primary-ip-address', 
    SOURCE_USER='repl_user', 
    SOURCE_PASSWORD='password', 
    SOURCE_AUTO_POSITION=1;
START REPLICA;

Option 2: If using Binary Log Position

SQL
-- Use the coordinates found in performance_schema.clone_status
CHANGE REPLICATION SOURCE TO 
    SOURCE_HOST='primary-ip-address', 
    SOURCE_USER='repl_user', 
    SOURCE_PASSWORD='password', 
    SOURCE_LOG_FILE='binlog.00000X', 
    SOURCE_LOG_POS=123;
START REPLICA;