- 2.2.1 Setting the Replication Master Configuration
- 2.2.2 Setting the Replication Slave Configuration
- 2.2.3 Creating a User for Replication
- 2.2.4 Obtaining the Replication Master Binary Log Coordinates
- 2.2.5 Choosing a Method for Data Snapshots
- 2.2.6 Setting Up Replication Slaves
- 2.2.7 Setting the Master Configuration on the Slave
- 2.2.8 Adding Slaves to a Replication Environment
This section describes how to set up a MySQL server to use binary log file position based replication. 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 setups:
On the master, you must ensure that binary logging is enabled, and configure a unique server ID. This might require a server restart. See Section 2.2.1, “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 2.2.2, “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 2.2.3, “Creating a User for Replication”.
Before creating a data snapshot or starting the replication process, on the master you should record the current position in the binary log. You need this information when configuring the slave so that the slave knows where within the binary log to start executing events. See Section 2.2.4, “Obtaining the Replication Master Binary Log Coordinates”.
If you already have data on the master and want to use it to synchronize the 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 using
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
MyISAMmaster, see Section 2.2.4, “Obtaining the Replication Master Binary Log Coordinates”. If you are using
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 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 2.2.7, “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 220.127.116.11, “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 18.104.22.168, “Setting Up Replication with Existing Data”.
To add replication slaves to an existing replication environment, see Section 2.2.8, “Adding Slaves to a Replication Environment”.
Before administering MySQL replication servers, read this entire chapter and try all statements mentioned in SQL Statements for Controlling Master Servers, and SQL Statements for Controlling Slave Servers. Also familiarize yourself with the replication startup options described in Section 2.6, “Replication and Binary Logging Options and Variables”.