Database replication copies changes from a source server to a replica. It can support read workloads or recovery arrangements, but it is not a backup: unwanted changes and deletions can also be copied.

Prepare both servers

Use compatible database versions and a documented replication method for that engine. MySQL and MariaDB are not interchangeable for replication configuration.

Before changing a production system, take verified backups, arrange any necessary downtime and confirm access to both servers. Restrict replication connections to the intended servers and use verified TLS where traffic crosses a network.

Configure and initialise replication

  1. Set a unique server-id on each server. Enable the required binary logging on the source and configure the replica according to its release’s documentation.
  2. Use the actual configuration files and service name for each installation. Do not expose the database on every interface merely to enable replication.
  3. Create a dedicated replication user restricted to the replica’s host, with only the required privileges.
  4. Take a consistent initial snapshot and record the matching binary-log file and position, or the corresponding GTID state. The capture method must suit the table engines and account for writes and schema changes.
  5. Restore that snapshot to a prepared replica. Keep application writes away from the replica during initialisation.
  6. Configure the connection using the coordinates belonging to that snapshot, then start replication.

Use statements for the installed engine

On MySQL 8.4, connection configuration uses CHANGE REPLICATION SOURCE TO, followed by:

START REPLICA;
SHOW REPLICA STATUS\G

On MariaDB, the documented connection configuration uses CHANGE MASTER TO, followed by:

START SLAVE;
SHOW SLAVE STATUS\G

The \G terminator is for the command-line database client. Set host, user, secret, transport verification and snapshot coordinates using the relevant engine’s documentation; do not copy credentials or positions from another installation.

Verify and monitor

Check both replication threads, recorded errors and replication delay. Compare expected data and test a controlled change in a test database before relying on the replica.

Keep independent backups and sufficient binary-log retention for disconnected replicas. Replication does not provide automatic failover by itself.