- 2.1.1 Setting the Replication Master Configuration
- 2.1.2 Setting the Replication Slave Configuration
- 2.1.3 Creating a User for Replication
- 2.1.4 Obtaining the Replication Master Binary Log Coordinates
- 2.1.5 Creating a Data Snapshot Using mysqldump
- 2.1.6 Creating a Data Snapshot Using Raw Data Files
- 2.1.7 Setting Up Replication with New Master and Slaves
- 2.1.8 Setting Up Replication with Existing Data
- 2.1.9 Introducing Additional Slaves to an Existing Replication Environment
- 2.1.10 Setting the Master Configuration on the Slave
This section describes how to set up complete replication of a MySQL server. 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 replication setups:
On the master, you must enable binary logging and configure a unique server ID. This might require a server restart. See Section 2.1.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.1.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.1.3, “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 will need this information when configuring the slave so that the slave knows where within the binary log to start executing events. See Section 2.1.4, “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. There are different methods to create the database snapshot, depending on the size of the database and the location of the files. Create a snapshot using mysqldump (see Section 2.1.5, “Creating a Data Snapshot Using mysqldump”) or by copying the data files directly (see Section 2.1.6, “Creating a Data Snapshot Using Raw Data Files”).
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.1.10, “Setting the Master Configuration on the Slave”.
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 2.1.7, “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 2.1.8, “Setting Up Replication with Existing Data”.
To add replication slaves to an existing replication environment, see Section 2.1.9, “Introducing Additional Slaves to an Existing 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.4, “Replication and Binary Logging Options and Variables”.
Certain steps within the setup process require the
SUPER privilege. If you do not
have this privilege, it might not be possible to enable