启用新的bin-log文件
mysql>flush logs;
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 | 120 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
insert into travelrecord(id,user_id,traveldate,fee,days) values(1002,‘1002‘,20160102,100,10);
UPDATE travelrecord SET user_id = ‘hahaha‘ WHERE id = 1002;
delete from travelrecord where id=1002;
用mysqlbinlog mysql-bin.000003查看具体误删除的时间
mysqlbinlog mysql-bin.000003
#180123 15:24:07 server id 101 end_log_pos 847 CRC32 0x8e720ef9 Query thread_id=20 exec_time=0 error_code=0
SET TIMESTAMP=1516692247/!/;
delete from travelrecord where id=1002
/!/;
.# at 847
此时备份数据库后在还原之前的备份数据。
mysql> set sql_log_bin=0; 临时关闭以免恢复过程生成大量的bin-log文件
mysql> use db1;
mysql> source /root/db1.sql;
mysqlbinlog --stop-datetime="2018-01-23 15:24:07 " mysql-bin.000003| mysql -uroot -p
查看数据库即可恢复数据。
原文:http://blog.51cto.com/13491150/2064263