当前位置:Gxlcms > 数据库问题 > mysql利用bin-log恢复误删除数据.

mysql利用bin-log恢复误删除数据.

时间:2021-07-01 10:21:17 帮助过:15人阅读

模拟备份数据库
mysqldump db1 > db1.sql

启用新的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

查看数据库即可恢复数据。

mysql利用bin-log恢复误删除数据.

标签:status   删除   val   数据库   误删除   mys   启用   sql   mysql   

人气教程排行