Recover data through binlog
What is binlog
binlog is mainly used for master-slave replication and data recovery
binlog brain map
How to check whether binlog is turned on? How to open
Explain that it is closed at this time, then how to open binlog?
server_id=2
log_bin = mysql-bin
binlog_format = statement
expire_logs_days = 30
restart mysql
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
, the actual location of the current log record
– 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;
At this time, if I mistakenly deleted the table
drop table ccc;
mysqlbinlog --no-defaults /usr/local/mysql/data/mysql-bin.000005
执行mysqlbinlog --no-defaults /usr/local/mysql/data/mysql-bin.000005 --start-position=154 --stop-position=1607 | mysql -uroot -proot wly_test1
Restored at this time
How to use row format to recover data?
mysqlbinlog --base64-output=decode-rows -v mysql-bin.000001