content_image/763731.jpg content_image/763744.jpg
mysql> SHOW BINARY LOGS; 

<img src='content_image/763731.jpg'>

With that information, you can use mysqlbinlog  to back up the binary log to the current directory as follows (enter each command on a single line): 

•To make a static backup of binlog.000130  through binlog.000132 , use either of these commands: 

mysqlbinlog --read-from-remote-server --host= host_name  --raw binlog.000130 binlog.000131 binlog.000132 

mysqlbinlog --read-from-remote-server --host= host_name  --raw --to-last-log binlog.000130 

The first command specifies every file name explicitly. The second names only the first file and uses --to-last-log  to read through the last. A difference between these commands is that if the server happens to open binlog.000133  before mysqlbinlog  reaches the end of binlog.000132 , the first command does not read it, but the second command does. 

•To make a live backup in which mysqlbinlog  starts with binlog.000130  to copy existing log files, then stays connected to copy new events as the server generates them: 

mysqlbinlog --read-from-remote-server --host= host_name  --raw --stop-never binlog.000130 

With --stop-never , it is not necessary to specify --to-last-log  to read to the last log file because that option is implied. 

## Output File Naming 

Without --raw , mysqlbinlog  produces text output and the --result-file  option, if given, specifies the name of the single file to which all output is written. With --raw , mysqlbinlog  writes one binary output file for each log file transferred from the server. By default, mysqlbinlog  writes the files in the current directory with the same names as the original log files. To modify the output file names, use the -- result-file  option. In conjunction with --raw , the --result-file  option value is treated as a prefix that modifies the output file names. 

Suppose that a server currently has binary log files named binlog.000999  and up. If you use mysqlbinlog --raw  to back up the files, the --result-file  option produces output file names as shown in the following table. You can write the files to a specific directory by beginning the --result- file  value with the directory path. If the --result-file  value consists only of a directory name, the value must end with the pathname separator character. Output files are overwritten if they exist. 

<img src='content_image/763744.jpg'>

## Example: mysqldump + mysqlbinlog for Backup and Restore 

The following example describes a simple scenario that shows how to use mysqldump  and mysqlbinlog together to back up a server’s data and binary log, and how to use the backup to restore the server if data 

