Skip to content

Seed a MySQL 8.4 replica with the CLONE plugin and GTID auto-positioning

Provision a MySQL 8.4 LTS read replica without mysqldump: enable GTIDs and binary logging, grant BACKUP_ADMIN and CLONE_ADMIN, run a remote CLONE INSTANCE FROM, then start replication with SOURCE_AUTO_POSITION=1 — including the syntax MySQL 8.4 removed outright.

MySQL 8.4 LTS gives you two pieces that, together, take most of the tedium out of building a read replica: the CLONE plugin, which streams a running instance’s InnoDB pages straight into an empty server over the network, and GTID auto-positioning, which lets that new server work out for itself where to resume reading the binary log. No overnight mysqldump, no staging directory for a physical backup, no binlog filename and offset copied by hand and mistyped at 2 a.m. This guide takes two MySQL 8.4 servers — db-a (source, 10.20.0.11) and db-b (replica, 10.20.0.12) — from a standalone install to a verified replication pair, and is explicit about the syntax 8.4 removed rather than merely deprecated, because that is where 8.0-era runbooks now fall over.

What you’ll accomplish

  • A source instance with binary logging and gtid_mode=ON, switched on without a restart if you cannot take one.
  • Two accounts on the source — BACKUP_ADMIN for the clone, REPLICATION SLAVE for the replication channel — and a local CLONE_ADMIN account on the replica.
  • A replica whose data directory was filled by one CLONE INSTANCE FROM statement, with the donor’s gtid_executed already inherited.
  • A running channel configured with SOURCE_AUTO_POSITION=1, verified through SHOW REPLICA STATUS and the performance_schema replication tables.
  • A list of the 8.0 statements that now return a syntax error, so your scripts get fixed once instead of failing twice.

Prerequisites

  • Two hosts running MySQL 8.4 LTS (8.4.0 or later), same version on both sides. The clone plugin will not copy between different MySQL versions, nor between different operating systems or architectures. Check SELECT VERSION(); on both before you plan anything.
  • All data in InnoDB. MyISAM and CSV tables are not cloned with their contents — they arrive empty, which is silent data loss if you do not check first.
  • Root or equivalent on both hosts, plus the ability to restart mysqld on the replica.
  • Free disk on the replica at least as large as the source’s data directory. The clone drops the replica’s existing data before writing, so the copies never coexist, but recovery still wants headroom.
  • Network reachability on 3306 from replica to source, and a plan for TLS. If the servers are not on one private network, read cross-region MySQL replication over TLS first — the certificate work there applies to the clone channel as much as the replication channel.
  • Honest version note: this all works on MySQL 8.0.17 and later too, but with the old keywords — CHANGE MASTER TO ... MASTER_AUTO_POSITION=1, START SLAVE. Those spellings were deprecated in 8.0.22/8.0.23 and removed in 8.4, where they now return a plain syntax error. This guide uses 8.4 spelling throughout.

How it works

A remote clone is a two-party operation. The donor is a normal, running MySQL server with the clone plugin loaded; it keeps serving traffic throughout. The recipient connects out to the donor as an ordinary client, drops whatever is in its own data directory, and receives InnoDB pages plus the redo generated during the copy. When the transfer finishes it restarts itself and performs InnoDB recovery, coming up as a consistent point-in-time copy of the donor.

Diagram of a MySQL 8.4 remote clone, showing the source donor with the clone plugin, log_bin and the BACKUP_ADMIN and REPLICATION SLAVE accounts, an arrow carrying InnoDB pages and gtid_executed to the recipient whose data directory is erased and refilled, a second arrow carrying the binlog stream, and a three-box handoff of recipient auto restart, gtid_purged being set, and pointing the replica at the source before starting replication

The part that matters for replication is the GTID handoff. The clone carries the donor’s gtid_executed set across and installs it on the recipient as gtid_purged. That single fact makes the next step trivial: the replica already knows, in globally unique transaction identifiers rather than file-and-offset coordinates, exactly which transactions it holds. Set SOURCE_AUTO_POSITION=1 and the replica hands that set to the source during the connection handshake; the source works out which binary log to start reading from. You never touch a coordinate.

Three things the clone does not do, and each one has bitten somebody:

  • It does not copy configuration files. server_id, gtid_mode and everything else in my.cnf stay whatever the replica’s own file says — which is what stops the replica coming up with a duplicate server_id.
  • It does not copy binary logs or relay logs. If the source purges a binlog the replica still needs, auto-positioning fails with a fatal error rather than silently skipping ahead.
  • It does copy the mysql schema — accounts, grants, everything. After the clone you authenticate against the replica with the donor’s credentials.

MySQL 8.4 also changed replication defaults you no longer need to set by hand. replica_parallel_workers defaults to 4 instead of 0, so multi-threaded apply is on out of the box, and replica_preserve_commit_order defaults to ON, keeping commit order identical to the source’s. binlog_transaction_dependency_tracking now defaults to WRITESET rather than COMMIT_ORDER, giving those workers far more to chew on; the variable is itself deprecated in 8.4, so leave it alone.

Step-by-step

First, confirm the clone plugin is the right tool for your data. It is the default answer for an all-InnoDB pair on matching versions, and the wrong answer in several common situations.

Comparison of three replica seeding methods: the CLONE plugin as the default for all-InnoDB MySQL 8.4 with the trade-offs that the recipient restarts itself and accounts are copied, mysqldump for mixed engines or cross-version and cross-OS moves, and a filesystem or LVM snapshot when a consistent copy already exists but the GTID position must be set by hand

  1. Turn on binary logging and GTIDs on the source. Binary logging is on by default in 8.4; GTIDs are not. Add this to /etc/mysql/mysql.conf.d/mysqld.cnf (Debian, Ubuntu) or /etc/my.cnf (RHEL family) on db-a:

    [mysqld]
    server_id                  = 1
    log_bin                    = /var/lib/mysql/binlog
    gtid_mode                  = ON
    enforce_gtid_consistency   = ON
    binlog_expire_logs_seconds = 1209600

    Restart, then confirm:

    sudo systemctl restart mysql
    mysql -e "SELECT @@server_id, @@gtid_mode, @@enforce_gtid_consistency, @@log_bin;"

    Expected: 1, ON, ON, 1. Note the retention value — fourteen days. Set it too short and a long clone plus a slow first sync will outrun the logs the replica needs.

  2. Or switch GTIDs on without a restart. If db-a is in production, MySQL supports an online transition. Run the steps in order and do not skip the check.

    SET @@GLOBAL.enforce_gtid_consistency = WARN;
    SET @@GLOBAL.enforce_gtid_consistency = ON;
    SET @@GLOBAL.gtid_mode = OFF_PERMISSIVE;
    SET @@GLOBAL.gtid_mode = ON_PERMISSIVE;
    SHOW STATUS LIKE 'Ongoing_anonymous_transaction_count';

    Expected: Ongoing_anonymous_transaction_count reaches 0. Only then:

    SET @@GLOBAL.gtid_mode = ON;

    Expected: Query OK. Leave WARN running a while first and watch the error log — it names any statement your application uses that GTID mode will not tolerate (CREATE TABLE ... SELECT, mixing transactional and non-transactional tables in one transaction). Write the settings into my.cnf afterwards, or the next restart undoes it.

  3. Create the two accounts on the source. They do different jobs. The clone account needs BACKUP_ADMIN; the replication account needs REPLICATION SLAVE — a privilege name that was not renamed in 8.4, which surprises people who expected the terminology change to be total.

    CREATE USER 'clone_src'@'10.20.0.%' IDENTIFIED BY 'CHANGE_ME_CLONE';
    GRANT BACKUP_ADMIN ON *.* TO 'clone_src'@'10.20.0.%';
    
    CREATE USER 'repl'@'10.20.0.%' IDENTIFIED BY 'CHANGE_ME_REPL' REQUIRE SSL;
    GRANT REPLICATION SLAVE ON *.* TO 'repl'@'10.20.0.%';

    Verify:

    SHOW GRANTS FOR 'clone_src'@'10.20.0.%';
    SHOW GRANTS FOR 'repl'@'10.20.0.%';

    Expected: GRANT BACKUP_ADMIN ON *.* for the first, GRANT REPLICATION SLAVE ON *.* for the second. Both get caching_sha2_password, because mysql_native_password is no longer enabled at startup in 8.4. Keep it that way and use TLS.

  4. Install the clone plugin on both servers. It ships with MySQL but is not loaded by default. Run this on db-a and again on db-b:

    INSTALL PLUGIN clone SONAME 'mysql_clone.so';
    SELECT PLUGIN_NAME, PLUGIN_STATUS FROM information_schema.PLUGINS
      WHERE PLUGIN_NAME = 'clone';

    Expected: one row, clone / ACTIVE. The registration lives in the mysql schema, so it survives restarts; to pin it in configuration instead, add plugin-load-add=mysql_clone.so to my.cnf.

  5. Prepare the replica’s configuration. db-b needs a distinct server_id and its own GTID settings, and should come up quiet rather than connecting to anything.

    [mysqld]
    server_id                = 2
    log_bin                  = /var/lib/mysql/binlog
    relay_log                = /var/lib/mysql/relay-bin
    gtid_mode                = ON
    enforce_gtid_consistency = ON
    skip_replica_start       = ON
    read_only                = ON
    super_read_only          = ON
    sudo systemctl restart mysql
    mysql -e "SELECT @@server_id, @@super_read_only, @@replica_parallel_workers;"

    Expected: 2, 1, 4. That 4 is the 8.4 default for replica_parallel_workers; on 8.0 the same query returns 0.

  6. Authorise the donor on the replica. The recipient will only clone from a host you have explicitly listed, and the local account running the statement needs CLONE_ADMIN. Setting the donor list is a global variable change, so grant SYSTEM_VARIABLES_ADMIN too — forgetting that is the most common stumble here.

    CREATE USER 'clone_admin'@'localhost' IDENTIFIED BY 'CHANGE_ME_ADMIN';
    GRANT CLONE_ADMIN, SYSTEM_VARIABLES_ADMIN ON *.* TO 'clone_admin'@'localhost';

    Then, connected as that account:

    SET GLOBAL clone_valid_donor_list = '10.20.0.11:3306';
    SELECT @@GLOBAL.clone_valid_donor_list;

    Expected: 10.20.0.11:3306 echoed back. The port is not optional, and the value is a comma-separated list rather than a pattern — wildcards are rejected.

  7. Run the clone. One statement on db-b, as clone_admin.

    CLONE INSTANCE FROM 'clone_src'@'10.20.0.11':3306
      IDENTIFIED BY 'CHANGE_ME_CLONE'
      REQUIRE SSL;

    Expected: Query OK, 0 rows affected after a long pause — or ERROR 2013 (HY000): Lost connection to MySQL server during query, equally normal, because the recipient restarts itself at the end and takes your session with it. Watch progress from a second session:

    SELECT STAGE, STATE, END_TIME FROM performance_schema.clone_progress;

    Expected: rows walking through DROP DATA, FILE COPY, PAGE COPY, REDO COPY, FILE SYNC, RESTART, RECOVERY, each moving to Completed. FILE COPY is where the time goes.

  8. Confirm the restart and the inherited GTID set. Reconnect once mysqld is back, using the donor’s credentials — the account table came across with everything else.

    SELECT STATE, ERROR_NO, BINLOG_FILE, BINLOG_POSITION
      FROM performance_schema.clone_status\G
    SELECT @@GLOBAL.gtid_purged\G

    Expected: STATE: Completed, ERROR_NO: 0, and a gtid_purged like 3e11fa47-71ca-11e1-9e33-c80aa9429562:1-58291 — the donor’s UUID and executed range. An empty gtid_purged means the source had GTIDs off when you cloned; go back to step 1.

  9. Point the replica at the source. This is the statement whose 8.0 spelling no longer parses.

    CHANGE REPLICATION SOURCE TO
      SOURCE_HOST = '10.20.0.11',
      SOURCE_PORT = 3306,
      SOURCE_USER = 'repl',
      SOURCE_PASSWORD = 'CHANGE_ME_REPL',
      SOURCE_SSL = 1,
      SOURCE_AUTO_POSITION = 1;

    Expected: Query OK, 0 rows affected plus warnings about storing the password in the replication metadata. That is why some teams pass credentials at start time with START REPLICA USER = ... PASSWORD = ... instead; neither approach is secret-safe on its own.

  10. Start replication and look at it immediately.

    START REPLICA;
    SHOW REPLICA STATUS\G

    Expected, in the fields that matter: Replica_IO_Running: Yes, Replica_SQL_Running: Yes, Auto_Position: 1, Last_IO_Error and Last_SQL_Error empty, and Seconds_Behind_Source counting down to 0. Retrieved_Gtid_Set goes non-empty within seconds of any write on the source.

Validate it works

Check the connection and the applier separately — SHOW REPLICA STATUS collapses two different failure modes into one screen.

SELECT SERVICE_STATE, LAST_ERROR_MESSAGE
  FROM performance_schema.replication_connection_status\G
SELECT WORKER_ID, SERVICE_STATE, LAST_ERROR_MESSAGE
  FROM performance_schema.replication_applier_status_by_worker;

Expected: SERVICE_STATE: ON with an empty error from the first, and four rows from the second, all ON — one per default parallel worker. Fewer than four means replica_parallel_workers was overridden somewhere.

Now prove data actually moves. On db-a:

CREATE DATABASE IF NOT EXISTS repl_check;
CREATE TABLE repl_check.beat (id INT PRIMARY KEY, seen TIMESTAMP);
INSERT INTO repl_check.beat VALUES (1, NOW());
SELECT @@GLOBAL.gtid_executed\G

On db-b, substituting the set you just read from the source for <source set>:

SELECT * FROM repl_check.beat;
SELECT GTID_SUBTRACT('<source set>', @@GLOBAL.gtid_executed) AS missing\G

Expected: the row appears, and missing is an empty string — the replica has executed every transaction the source has. A non-empty missing that shrinks on re-run is lag; one that does not shrink is a stall.

Finally, confirm the replica cannot be written to by accident:

mysql -e "SELECT @@read_only, @@super_read_only;"

Expected: 1 and 1. Without super_read_only, any account holding CONNECTION_ADMIN can still write and break the GTID chain.

Troubleshooting

  • ERROR 1064 on START SLAVE, SHOW SLAVE STATUS or CHANGE MASTER TO. Not deprecated — gone. Substitute START REPLICA, SHOW REPLICA STATUS and CHANGE REPLICATION SOURCE TO. The other removals that catch scripts: SHOW MASTER STATUS is now SHOW BINARY LOG STATUS, SHOW SLAVE HOSTS is SHOW REPLICAS, RESET SLAVE is RESET REPLICA, and RESET MASTER is RESET BINARY LOGS AND GTIDS. Grep your runbooks for MASTER_ and SLAVE in one pass.
  • The clone fails with a donor error naming BACKUP_ADMIN. The recipient wraps the donor’s error, so the message describes a privilege on a server you are not connected to. Check SHOW GRANTS FOR 'clone_src'@'10.20.0.%'; on db-a. A near-identical failure happens when the host pattern does not match the replica’s source address.
  • The clone is rejected before it starts, naming clone_valid_donor_list. Either the variable is empty, or you set it without the port, or you set it per session. It is global only. Re-run SET GLOBAL clone_valid_donor_list = 'host:port'; as an account with SYSTEM_VARIABLES_ADMIN.
  • The recipient never comes back, with Restart server failed (mysqld is not managed by supervisor process). The clone finished but the auto-restart could not fire, because mysqld was started by hand rather than under systemd or mysqld_safe. Nothing is lost: sudo systemctl start mysql, let recovery finish, then check performance_schema.clone_status for Completed.
  • Replica_IO_Running: Connecting with an authentication error mentioning caching_sha2_password. In 8.4 mysql_native_password is off at startup, so repl uses caching_sha2_password, which will not send credentials over a plaintext channel unless it can fetch the source’s public key. Keep SOURCE_SSL = 1 — the right answer — or, on a trusted private link, add GET_SOURCE_PUBLIC_KEY = 1 to the CHANGE REPLICATION SOURCE TO statement.
  • Got fatal error 1236 saying the source purged binary logs containing GTIDs the replica requires. The gap between the cloned snapshot and the oldest surviving binary log is real and no restart will bridge it. This is what binlog_expire_logs_seconds was for in step 1: raise retention on the source, then clone again.

When this is the wrong approach

The clone plugin only understands InnoDB. If the schema still carries MyISAM or CSV tables, those arrive empty and replication then happily applies changes to rows that were never seeded. Convert them first with ALTER TABLE ... ENGINE=InnoDB, or seed with mysqldump and accept the slower restore.

It also will not cross a version or a platform boundary. Moving from 8.0 to 8.4, from x86 to ARM, or from RHEL to Ubuntu means a logical dump. The same goes for MariaDB in either direction: there is no clone plugin there, and its GTID implementation is a different design with different syntax.

On managed platforms — RDS, Aurora, Cloud SQL — you do not get CLONE_ADMIN and you do not need it: use the provider’s read-replica feature, which does the equivalent work underneath. Shared hosting is its own category; see adding a MySQL read replica to a cPanel account for what is possible when the control panel owns the configuration.

Finally, remember what a replica is not. It follows the source, including the DROP TABLE somebody ran at 4 p.m. It protects you from a dead server, not from a bad statement, so it belongs alongside real backups rather than in place of them.

Keep the MySQL 8.4 clone plugin documentation and the replication with GTIDs chapter open while you work.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.