MySQL 5.6 Reference Manual Including MySQL NDB Cluster 7.3-7.4 Reference Guide
To configure the replica to start the replication process at the correct point, you need to note the source's current coordinates within its binary log.
This procedure uses FLUSH TABLES WITH
READ LOCK
, which blocks
COMMIT
operations for
InnoDB
tables.
If you have existing data on your source server that you want to synchronize on your replicas before starting the replication process, you must stop processing statements on the source, and then obtain its current binary log coordinates and dump its data, before permitting the source to continue executing statements. If you do not stop the execution of statements, the data dump and the source status information that you use does not match and you may end up with inconsistent or corrupted databases on the replicas.
If you are planning to shut down the source to create a data snapshot, you can optionally skip this procedure and instead store a copy of the binary log index file along with the data snapshot. In that situation, the source creates a new binary log file on restart. The source's binary log coordinates where the replica must start the replication process are therefore the start of that new file, which is the next binary log file on the source following after the files that are listed in the copied binary log index file.
To obtain the source's binary log coordinates, follow these steps:
Start a session on the source by connecting to it with the
command-line client, and flush all tables and block write
statements by executing the FLUSH
TABLES WITH READ LOCK
statement:
mysql> FLUSH TABLES WITH READ LOCK;
Leave the client from which you issued the
FLUSH TABLES
statement
running so that the read lock remains in effect. If you
exit the client, the lock is released.
In a different session on the source, use the
SHOW MASTER STATUS
statement
to determine the current binary log file name and position:
mysql > SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 | 73 | test | manual,mysql |
+------------------+----------+--------------+------------------+
The File
column shows the name of the log
file and Position
shows the position
within the file. In this example, the binary log file is
mysql-bin.000003
and the position is 73.
Record these values. You need them later when you are
setting up the replica. They represent the replication
coordinates at which the replica should begin processing new
updates from the source.
If the source has been running previously without binary
logging enabled, the log file name and position values
displayed by SHOW MASTER
STATUS
or mysqldump
--master-data is empty. In that case, the values
that you need to use later when specifying the binary log
file and position are the empty string
(''
) and 4
.
You now have the information you need to enable the replica to start reading from the binary log in the correct place to start replication.
If you have existing data that needs be to synchronized with the replica before you start replication, leave the client running so that the lock remains in place and then proceed to Section 17.1.1.5, “Creating a Data Snapshot Using mysqldump”, or Section 17.1.1.6, “Creating a Data Snapshot Using Raw Data Files”. The idea here is to prevent any further changes so that the data copied to the replicas is in synchrony with the source.
If you are setting up a brand new source and replica replication group, you can exit the first session to release the read lock.