DBAtlas · Database operations atlas

Set up a replica (CHANGE REPLICATION SOURCE)

MySQLReplication

Command

CHANGE REPLICATION SOURCE TO SOURCE_HOST='source_host', SOURCE_PORT=3306, SOURCE_USER='replicator', SOURCE_PASSWORD='secret', SOURCE_AUTO_POSITION=1;

What it does

Configures this server as a replica that follows the specified source using GTID-based auto-positioning.

When to use it

To set up a new replica or change the replication source.

Caution

This is MySQL 8.0.23+ terminology; older versions use CHANGE MASTER TO ... MASTER_HOST (an alias in 8.0.23–8.3, removed in 8.4). SOURCE_AUTO_POSITION=1 requires GTID to be enabled (gtid_mode=ON); otherwise SOURCE_LOG_FILE and SOURCE_LOG_POS must be specified. Replication must be stopped before running the command. If the replication user was created with the 8.0+ default caching_sha2_password, the connection requires TLS: add SOURCE_SSL=1 or, without TLS, set GET_SOURCE_PUBLIC_KEY=1; otherwise the I/O thread fails to connect with error 2061.

Open in DBAtlas →

Related