This section describes how to set up replication of a MySQL server using binary logging. There are a number of different methods for setting up replication, and the exact method to use depends on how you are setting up replication, and whether you already have data within your master database.
There are some generic tasks that are common to all binary log based replication setups:
On the master, you must enable binary logging and configure a unique server ID. This might require a server restart. See Section 18.104.22.168, “Setting the Replication Master Configuration”.
On each slave that you want to connect to the master, you must configure a unique server ID. This might require a server restart. See Section 22.214.171.124, “Setting the Replication Slave Configuration”.
Optionally, create a separate user for your slaves to use during authentication with the master when reading the binary log for replication. See Section 126.96.36.199, “Creating a User for Replication”.
Before creating a data snapshot or starting the replication process, you should record the position of the binary log on the master. You need this information when configuring the slave so that the slave knows where within the binary log to start executing events. See Section 188.8.131.52, “Obtaining the Replication Master Binary Log Coordinates”.
If you already have data on your master and want to use it to
synchronize your slave, you need to create a data snapshot to
copy the data to the slave. The storage engine you are using
has an impact on how you create the snapshot. When you are
MyISAM, you must stop
processing statements on the master to obtain a read-lock,
then obtain its current binary log coordinates and dump its
data, before permitting the master to continue executing
statements. If you do not stop the execution of statements,
the data dump and the master status information will not
match, resulting in inconsistent or corrupted databases on the
slaves. For more information on replicating a
MyISAM master, see
Section 184.108.40.206, “Obtaining the Replication Master Binary Log Coordinates”. If you are
InnoDB, you do not need a
read-lock and a transaction that is long enough to transfer
the data snapshot is sufficient. For more information, see
Section 14.17, “InnoDB and MySQL Replication”.
Configure the slave with settings for connecting to the master, such as the host name, login credentials, and binary log file name and position. See Section 220.127.116.11, “Setting the Master Configuration on the Slave”.
Certain steps within the setup process require the
SUPER privilege. If you do not
have this privilege, it might not be possible to enable
After configuring the basic options, select your scenario:
To set up replication for a fresh installation of a master and slaves that contain no data, see Section 18.104.22.168.1, “Setting Up Replication with New Master and Slaves”.
To set up replication of a new master using the data from an existing MySQL server, see Section 22.214.171.124.2, “Setting Up Replication with Existing Data”.
To add replication slaves to an existing replication environment, see Section 126.96.36.199, “Adding Slaves to a Replication Environment”.
Before administering MySQL replication servers, read this entire chapter and try all statements mentioned in Section 13.4.1, “SQL Statements for Controlling Master Servers”, and Section 13.4.2, “SQL Statements for Controlling Slave Servers”. Also familiarize yourself with the replication startup options described in Section 17.1.6, “Replication and Binary Logging Options and Variables”.