MySQL replication copies database changes from a source server to a replica. Preparing the source, formerly called the master, requires a unique server ID, binary logging and a restricted replication account.
Plan the replication setup
These examples cover MySQL, not an interchangeable MariaDB procedure. Confirm version compatibility, take verified backups and plan the replica’s initial snapshot and position or GTID configuration. Restrict the database port to the replica through an approved private network or firewall policy.
Check source configuration
-
Connect using an authorised database administrator account.
-
Inspect the current settings:
SELECT @@server_id, @@log_bin, @@bind_address; -
Locate the configuration file read by this MySQL installation. Common paths include
/etc/my.cnfand/etc/mysql/mysql.conf.d/mysqld.cnf; included files can override values. -
Under
[mysqld], configure a unique non-zero server ID. Where binary logging needs enabling or an explicit basename, use separate valid settings, for example:[mysqld] server-id = 1 log-bin = mysql-bin bind-address = 10.0.0.10Replace
1if it is already used in the topology, and replace the example address with an address actually assigned to the source and reachable by the replica. Do not change an existing binary-log basename without assessing replication effects. -
Back up and validate the configuration using the installed version’s supported method. Apply changes through a planned restart only where required, using the correct service for the installation. Check that MySQL starts and the expected settings are active.
Create a restricted replication account
For an example replica whose connection reaches the source from 10.0.0.20, run as an authorised administrator:
CREATE USER 'replica_user'@'10.0.0.20'
IDENTIFIED BY 'replace-with-a-unique-password' REQUIRE SSL;
GRANT REPLICATION SLAVE ON *.* TO 'replica_user'@'10.0.0.20';Use the actual source-visible replica address and a unique password. Configure trusted certificates and TLS on both ends so the replica can meet the encrypted-connection requirement. SQL retains the historical privilege name even when documentation calls the server a replica.
Complete the replica separately
Source settings alone do not start replication. Configure the replica from a consistent snapshot with matching coordinates or the planned GTID method, then check replication status and errors. Replication also copies unwanted changes and is not a replacement for independent backups.