The mysqldump
command in MySQL is used to create a backup of databases. The option --dump-slave[=#]
allows including the slave replication coordinates in the output of the dump, although it is now deprecated.
Here are several examples demonstrating the usage of --dump-slave
:
Example 1: Dumping with slave position:
mysqldump --dump-slave=2 -u root -p mydatabase > dump_with_slave.sql
This command dumps the database mydatabase
along with the replication coordinates up to 2 seconds behind the master. The output is redirected to dump_with_slave.sql
.
Verification Steps: To verify, open dump_with_slave.sql
and look for lines similar to:
-- CHANGE MASTER TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=123456789;
Example 2: Dumping without specifying a time limit:
mysqldump --dump-slave -u root -p mydatabase > dump_with_full_slave.sql
This command dumps the database mydatabase
with the current slave replication coordinates. The output is saved to dump_with_full_slave.sql
.
Verification Steps: Check dump_with_full_slave.sql
for lines indicating the replication coordinates.
Example 3: Dumping without including slave coordinates:
mysqldump -u root -p mydatabase > dump_without_slave.sql
This command creates a standard dump of mydatabase
without including any slave replication coordinates. The output is directed to dump_without_slave.sql
.
Verification Steps: Inspect dump_without_slave.sql
to ensure there are no lines related to replication coordinates.
Example 4: Using --dump-slave
with a zero delay:
mysqldump --dump-slave=0 -u root -p mydatabase > dump_with_zero_delay.sql
This command dumps the database mydatabase
with the current replication coordinates, ensuring no delay. The output is saved to dump_with_zero_delay.sql
.
Verification Steps: Check dump_with_zero_delay.sql
for immediate replication coordinates.
Example 5: Attempting to use a deprecated syntax:
mysqldump --dump-slave -u root -p mydatabase > dump_deprecated_syntax.sql
This command demonstrates using the deprecated syntax for including slave replication coordinates. It may still work but is not recommended for new scripts.
Verification Steps: Verify the output file dump_deprecated_syntax.sql
for any replication coordinate lines.
These examples showcase different uses of the --dump-slave
option in mysqldump
for MySQL, illustrating how to include or exclude slave replication coordinates in your database backups.
Also check similar articles.
Dumping Replica Position in mysqldump Output
Disabling Keys in mysqldump Output
Deleting Master Logs in mysqldump (Deprecated)
Rotating Logs Before Backup in mysqldump
Setting Default Character Set in mysqldump
Discussion about this post