Pre-General Availability Draft: 2017-10-20
- 220.127.116.11 Setting the Replication Master Configuration
- 18.104.22.168 Setting the Replication Slave Configuration
- 22.214.171.124 Creating a User for Replication
- 126.96.36.199 Obtaining the Replication Master Binary Log Coordinates
- 188.8.131.52 Choosing a Method for Data Snapshots
- 184.108.40.206 Setting Up Replication Slaves
- 220.127.116.11 Setting the Master Configuration on the Slave
- 18.104.22.168 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 22.214.171.124, “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 126.96.36.199, “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 188.8.131.52, “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 184.108.40.206, “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 220.127.116.11, “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 Section 15.18, “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 18.104.22.168, “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 22.214.171.124.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 126.96.36.199.2, “Setting Up Replication with Existing Data”.
To add replication slaves to an existing replication environment, see Section 188.8.131.52, “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 18.1.6, “Replication and Binary Logging Options and Variables”.