Mysql binary log backup and restore
First, open the binary log
Adding a configuration, the configuration file into the [mysqld] at
Option One
vim /etc/my.cnf
log-bin = /usr/local/mysql/logs/mysql_bin
max_binlog_size = 100M
Option II
vim /etc/my.cnf.d/server.cnf
log_bin = ' binary log name '
2, restart the service
systemctl restart mysqld
3, view the binary log into the mysql open state
show variables like 'log_bin';
Second, use the command
- # View binary log start state
- show variables like 'log_bin';
- # View log binary log is being used
- show master status;
- # View all binary logs
- show master logs;
- # Visualize the contents of binary files
- show binlog events in 'mysql_bin.000001';
- # View binary file contents # at 678 to position the value of the time value of 3:44:14 # 1321312
- mysqlbinlog --stop-position=795 /xxx/mysql_bin.000001 >/xxx/mysql_bin_001.sql
- cat /xxx/mysql_bin_001.sql
- # Recover according to position
- mysqlbinlog --start-position=1 --stop-position=795 /xxx/mysql_bin.000001 | mysql -uroot -p123123
- # Depending on the timing recovery position; -d specified database, specify the options -h host
- mysqlbinlog --start-date = "2010-09-29 18:00:00" --stop-date = "2010-09-29 23:00:00" -d -h library name address /xxx/mysql_bin.000001 | mysql -uroot -p123123
- # All the data records of all binary log files recovery
- mysqlbinlog /xxx/mysql_bin.000001 |mysql -uroot -p123123
- # Re-establish a new binary log file
- flush logs;
- # Clear all binary logs
- reset master;