When setting up replication with existing data, transfer the snapshot from the source to the replica before starting replication. The process for importing data to the replica depends on how you created the snapshot of data on the source.
Follow this procedure to set up replication with existing data:
Import the data to the replica using one of the following methods:
If you used mysqldump, start the replica server, ensuring that replication does not start by using the
--skip-slave-startoption. Then import the dump file:
$> mysql < fulldb.dump
If you created a snapshot using the raw data files, extract the data files into your replica's data directory. For example:
$> tar xvf dbdump.tar
You may need to set permissions and ownership on the files so that the replica server can access and modify them. Then start the replica server, ensuring that replication does not start by using the
Configure the replica with the replication coordinates from the source. This tells the replica the binary log file and position within the file where replication needs to start. Also, configure the replica with the login credentials and host name of the source. For more information on the
CHANGE MASTER TOstatement required, see Section 18.104.22.168, “Setting the Source Configuration on the Replica”.
Start the replication threads:
mysql> START SLAVE;
After you have performed this procedure, the replica connects to the source and replicates any updates that have occurred on the source since the snapshot was taken.
variable for the source is not correctly set, replicas cannot
connect to it. Similarly, if you have not set
server_id correctly for the
replica, you get the following error in the replica's error
Warning: You should set server-id to a non-0 value if master_host is set; we will force server id to 2, but this MySQL server will not act as a slave.
You also find error messages in the replica's error log if it is not able to replicate for any other reason.
The replica stores information about the source you have
configured in its connection metadata repository. The
connection metadata repository can be in the form of files or
a table, as determined by the value set for the
variable. When a replica runs with
two files are stored in the data directory, named
instead, this information is saved in the
master_slave_info table in the
mysql database. In either case, do
not remove or edit the files or table.
Always use the
CHANGE MASTER TO
statement to change replication parameters. The replica can
use the values specified in the statement to update the status
files automatically. See Section 5.4, “Relay Log and Replication Metadata Repositories”, for
The contents of the connection metadata repository override
some of the server options specified on the command line or
Section 2.6, “Replication and Binary Logging Options and Variables”, for more details.
A single snapshot of the source suffices for multiple replicas. To set up additional replicas, use the same source snapshot and follow the replica portion of the procedure just described.