Simulating a backup database
Mysqldump DB1 > Db1.sql
To enable the new Bin-log file
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;
Use Mysqlbinlog mysql-bin.000003 to see how long a specific error was deleted
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
Backup data before you restore the database at this time.
Mysql> set sql_log_bin=0; Temporary shutdown to avoid the recovery process generating a large number of bin-log files
mysql> use DB1;
Mysql> Source/root/db1.sql;
Mysqlbinlog--stop-datetime= "2018-01-23 15:24:07" mysql-bin.000003| Mysql-uroot-p
You can recover data by viewing the database.
MySQL uses Bin-log to recover deleted data by mistake.