导读:将数据库回档至指定时间点或位置,常常是使用全量备份+binlog增量实现的。
先解析成sql文件,再导入MySQL
- mysqlbinlog mysql-bin.000001
- mysqlbinlog mysql-bin.000002 ... mysql-bin.n >> /data/add.sql
- mysql -u -p -S < /data/add.sql
直接管道到MySQL中
- mysqlbinlog mysql-bin.000001
- mysqlbinlog mysql-bin.000002 ... mysql-bin.n | mysql -u -p -S
直接管道进去的方式,并不一定安全,手册上也有指明:
If you have more than one binary log to execute on the MySQL server,
the safe method is to process them all using a single connection to the server.
关于这种方式的更多内容,可以参考:
https://dev.mysql.com/doc/refman/5.7/en/point-in-time-recovery.html
然而这两种方式原理都是一样的,通过mysqlbinlog解析成sql并导入到MySQL中。
优点:
操作方便,逻辑简单。
无需关闭mysqld。
缺点:
遇到ERROR难以定位位置,难以“断点恢复”。
特殊字符或字符集的问题。
max_allowed_packet问题。
恢复速度慢。