The mysqldump
command in MySQL is used for creating logical backups of databases. One useful option is --source-data[=#]
, which allows appending the binary log position in the output of mysqldump. This option is particularly handy when you need to record the exact position in the binary log from which the dump was taken.
Here are some examples of how to use --source-data
with mysqldump:
Example 1: Append binary log position with a specified number of digits (e.g., 6 digits):
mysqldump --source-data=6 --all-databases > backup.sql
This command creates a backup of all databases with the binary log position appended, using 6 digits to represent the position.
Example 2: Append binary log position with default settings:
mysqldump --source-data --databases db1 db2 > backup.sql
This command dumps databases db1
and db2
with the binary log position appended in the output file backup.sql
.
Example 3: Append binary log position and specify the number of digits interactively:
mysqldump --source-data=# --databases db3 > backup.sql
Here, you’ll be prompted to enter the number of digits to use for the binary log position in the output file backup.sql
for database db3
.
To verify if the mysqldump
command executed successfully and appended the binary log position, you can open the generated backup file using a text editor or command-line tool. Search for a line near the beginning or end of the file that contains the binary log position information. The format typically shows something like “-- CHANGE MASTER TO MASTER_LOG_FILE='xxxxx', MASTER_LOG_POS=yyyyy;
” depending on MySQL version and configuration.
Also check similar articles.
Setting Long Query Time for mysqldump
Logging Errors to File in mysqldump
Locking Tables for Read in mysqldump
Locking All Tables Across Databases in mysqldump
Setting Line Terminator in mysqldump Output
Discussion about this post