MySQL uses Bin-log to recover deleted data by mistake.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.