-- 2019-08-09 11:01:54之前的數(shù)據(jù)條數(shù)chengqm-3306>>select count(*) from mytest.mytest where ctime < '2019-08-09 11:01:54';+----------+| count(*) |+----------+| 161 |+----------+1 row in set (0.00 sec) -- 所有數(shù)據(jù)條數(shù)chengqm-3306>>select count(*) from mytest.mytest;+----------+| count(*) |+----------+| 180 |+----------+1 row in set (0.00 sec)
然后執(zhí)行恢復(fù)
# 全量恢復(fù)[mysql@mysql-test ~]$ mysql -S /tmp/mysql.sock < backup.sql # 應(yīng)用增量日志[mysql@mysql-test ~]$ mysql -S /tmp/mysql.sock < backup_inc.sql
檢查數(shù)據(jù)
chengqm-3306>>select count(*) from mytest.mytest;+----------+| count(*) |+----------+| 161 |+----------+1 row in set (0.00 sec) chengqm-3306>>select * from mytest.mytest order by id desc limit 5;+-----+---------------------+| id | ctime |+-----+---------------------+|161| 2019-08-09 11:01:53 || 160 |2019-08-09 11:01:52||159| 2019-08-09 11:01:51 || 158 |2019-08-09 11:01:50||157| 2019-08-09 11:01:49 |+-----+---------------------+5 rows in set (0.00 sec)
[mysql@mysql-test ~]$ mysql -S /tmp/mysql.sock < backup.sql
全量恢復(fù)后狀態(tài)
chgnqm-3306>>show tables;+------------------+| Tables_in_mytest |+------------------+| a || b |+------------------+2 rows in set (0.00 sec) chgnqm-3306>>select count(*) from a;+----------+| count(*) |+----------+| 71 |+----------+1 row in set (0.00 sec)
5 恢復(fù)增量數(shù)據(jù)
[mysql@mysql-test ~]$ mysql -S /tmp/mysql.sock < backup_inc_1.sql[mysql@mysql-test ~]$ mysql -S /tmp/mysql.sock < backup_inc_2.sql
恢復(fù)后狀態(tài),可以看到已經(jīng)跳過(guò)了 drop 語(yǔ)句
chgnqm-3306>>show tables;+------------------+| Tables_in_mytest |+------------------+| a || b |+------------------+2 rows in set (0.00 sec) chgnqm-3306>>select count(*) from a;+----------+| count(*) |+----------+| 274 |+----------+1 row in set (0.00 sec)
chengqm-3307>>show slave status \G;...Slave_IO_Running: YesSlave_SQL_Running: Yes...1 row in set (0.00 sec) chengqm-3307>>show tables;+------------------+| Tables_in_mytest |+------------------+| a || b |+------------------+2 rows in set (0.00 sec)
閃回 閃回操作就是反向操作,比如執(zhí)行了 delete from a where id=1,閃回就會(huì)執(zhí)行對(duì)應(yīng)的插入操作 insert into a (id,...) values(1,...),用于誤操作數(shù)據(jù),只對(duì) DML 語(yǔ)句有效,且要求 binlog 格式設(shè)為 ROW。本章介紹兩個(gè)比較好用的開(kāi)源工具 binlog2sql binlog2sql 是大眾點(diǎn)評(píng)開(kāi)源的一款用于解析 binlog 的工具,可以用于生成閃回語(yǔ)句,項(xiàng)目地址 binlog2sql(https://sourl.cn/ZuNJPN) 安裝