How to recover data through binlog

What is binlog

binlog is mainly used for master-slave replication and data recovery
Insert picture description here

binlog brain map

Insert picture description here

How to check whether binlog is turned on? How to open

Insert picture description here

Explain that it is closed at this time, then how to open binlog?
Insert picture description here
server_id=2
log_bin = mysql-bin
binlog_format = statement
expire_logs_days = 30
restart mysql
Insert picture description here
Insert picture description here

There are several formats of binlog

1. The statement currently uses this
2. If row is not configured, the default is row mysql 5.7 or higher
3. Mixed

How to recover data through binlog in mysql

Let’s first create a table, the
current state
Insert picture description here
, the actual location of the current log record
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Insert picture description here

– Create a table
crete table eee (id.int,c1 varchar(100),c2 varchar(100))
insert into eee(id, c1,c2) ​​values ​​(1,'test 1c1','test c2');
insert into eee(id, c1,c2) ​​values ​​(1,'test 2c1','test c2');
insert into eee(id, c1,c2) ​​values ​​(1,'test 3c1','test c2');
– update /Delete
update ccc set c2='modify' where id=2;

Insert picture description here
Insert picture description here

At this time, if I mistakenly deleted the table
drop table ccc;
Insert picture description here
Insert picture description here
mysqlbinlog --no-defaults /usr/local/mysql/data/mysql-bin.000005

Insert picture description here
Insert picture description here
Insert picture description here

执行mysqlbinlog --no-defaults /usr/local/mysql/data/mysql-bin.000005 --start-position=154 --stop-position=1607 | mysql -uroot -proot wly_test1
Insert picture description here

Restored at this time
Insert picture description here

How to use row format to recover data?
Insert picture description here
mysqlbinlog --base64-output=decode-rows -v mysql-bin.000001
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_37509194/article/details/110005619