To create a snapshot of the data in an existing master database, use the mysqldump tool. Once the data dump has been completed, import this data into the slave before starting the replication process.
The following example dumps all databases to a file named
dbdump.db, and includes the
--master-data option which
automatically appends the
TO statement required on the slave to start the
shell> mysqldump --all-databases --master-data > dbdump.db
If you do not use
--master-data, then it is
necessary to lock all tables in a separate session manually.
See Section 2.2.4, “Obtaining the Replication Master Binary Log Coordinates”.
It is possible to exclude certain databases from the dump
using the mysqldump tool. If you want to
choose which databases to include in the dump, do not use
--all-databases. Choose one
of these options:
For more information, see mysqldump — A Database Backup Program.
To import the data, either copy the dump file to the slave, or access the file from the master when connecting remotely to the slave.