1.MySQL开启binlog功能
log-error=/var/log/mysql.log
log-bin=/data/binlog/mysql-bin
sync_binlog=1
binlog_format=row
2.登录到数据库
[root@db01 ~]# mysql -uroot -p123
3.创建与删除数据库
mysql> create database xiaohai;
mysql> drop database xiaohai;
4.查看binlog日志
[root@db01 binlog]# mysqlbinlog mysql-bin.000008
# at 1200
#200409 16:41:36 server id 10 end_log_pos 1297 CRC32 0x84e92ac7 Query thread_id=8 exec_time=0 error_code=0
SET TIMESTAMP=1586421696/*!*/;
create database xiaohai
/*!*/;
# at 1297
#200409 16:42:24 server id 10 end_log_pos 1384 CRC32 0xfdf1d747 Query thread_id=8 exec_time=0 error_code=0
SET TIMESTAMP=1586421744/*!*/;
drop database xiaohai
/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
5.恢复数据
[root@db01 binlog]# mysqlbinlog mysql-bin.000008 --start-position=1200 --stop-position=1297>test.sql
mysql> source /data/binlog/test.sql;
mysql> show databases;
来源:oschina
链接:https://my.oschina.net/u/4399548/blog/3228951