mysql use mysqlbinlog command to recover accidentally deleted data

lab environment:
MYSQL 5.7.22
Chi open binary log
Log Format MIXED
experiment procedure:
1, execute: FLUSH LOGS;
master-bin.000014 new file is generated files
 
 
Experimental log to refresh the content more intuitive and easier to observe the content of the entire course of the experiment.
I have seen many articles online using REST MASTER; but not explain the seriousness of this command
This command deletes all log files and the file name is reset to zero and record the point, 99% of the cases is less than this command
Delete Logs can use PURGE MASTER LOGS ... so little insurance
2, a new log file has been generated, the first look at the content, there are a few points you need to know
 
 
View binary file date log command: mysqlbinlog master-bin.000014
# at 4
#180903 16:19:12 server id 1  end_log_pos 123 CRC32 0xe03659b3  Start: binlog v 4, server v 5.7.22-log created 180903 16:19:12
Look at the top two arrows:
# At 4 (event starting point)
# 180903 16:19:12 (representative of the time)
server id 1 (specify the primary and backup copy for each unique database MYSQL SERVER ID, I is not configured by default 1)
end_log_pos 123 (event end point)
Look below two arrows:
# At 123 (event starting point and end point of the top event is the corresponding)
end_log_pos 154 (event end point)
at between 4 and at 123 the content is the content of the event
3, simulated business scenarios, build tables, insert data, and finally remove a table; for real, I built two libraries, and write to different libraries, and finally delete a table in a library.
mysql> FLUSH LOGS;
Query OK, 0 rows affected (0.01 sec)
mysql> create database t1;
Query OK, 1 row affected (0.03 sec)
mysql> create database t2;
Query OK, 1 row affected (0.00 sec)
mysql> use t1;
Database changed
mysql> create table t1 (id int);
Query OK, 0 rows affected (0.03 sec)
mysql> use t2;
Database changed
mysql> create table t2 (id int);
Query OK, 0 rows affected (0.03 sec)
mysql> insert into t2 values (3);
Query OK, 1 row affected (0.01 sec)
mysql> insert into t2 values (4);
Query OK, 1 row affected (0.01 sec)
mysql> use t1;
Database changed
mysql> insert into t1 values (1);
Query OK, 1 row affected (0.01 sec)
mysql> insert into t1 values (2);
Query OK, 1 row affected (0.01 sec)
mysql> use t2;
Database changed
mysql> insert into t2 values(20);
Query OK, 1 row affected (0.01 sec)
mysql> use t1;
Database changed
mysql> insert into t1 values(10);
Query OK, 1 row affected (0.01 sec)
mysql> drop table t1;
Query OK, 0 rows affected (0.02 sec)
mysql> use t2;
Database changed
mysql> insert into t2 values(222);
Query OK, 1 row affected (0.01 sec)
mysql>
Establishing T1, T2 library, establishing T1, T2 table.
To insert data T1: 1,2,10
To insert data T2: 3,4,20,222
Simulation scenarios, delete tables T1, T2 T2 table library service continues to run
 
The T1 will now be restored through the log table.
First you have to find the delete command log points:
mysqlbinlog master-bin.000014|grep -5a "DROP TABLE"
 
 
See #AT 2439 (a note of this number)
DROP TABLE point in this event to perform.
Since the log T1 not only library in the log file, as well as T2 library logs will take only a database log T1
And also just take the log log point before 2439, then re-apply
If we take log 2439, then again when the database will be re-building a database application to build the table, insert data, delete the table will be the implementation of this statement.
 
 mysqlbinlog -d t1 --stop-position = 2439 master-bin.000014> test.sql (actually execute this statement being given)
WARNING: The option --database has been used. It may filter parts of transactions, but will include the GTIDs in any case. If you want to exclude or include transactions, you should use the options --exclude-gtids or --include-gtids, respectively, instead.
暂时弄不清楚原因,百度了下修改成:
mysqlbinlog master-bin.000014 -d t1  --skip-gtids --stop-position=2439>test.sql
-d: specifies the parameter is a database log
Command means that before the 2439 master-Point Log bin.000014日志文件内的 T1 database logs, events, output to test.sql
# tail test.sql
Look at the last few lines of the file
 
Log database:
mysql> use t1;
Database changed
mysql> source test.sql
A middle error, because building a database that contains T1 inside the statement.
View the table of contents
 
 
So that data back.
----------------
Disclaimer: This article is CSDN bloggers 'fuel vinegar 0' original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/chaigang/article/details/82350399

Guess you like

Origin www.cnblogs.com/yaoyangding/p/12237352.html