开启binlog日志:

创建目录并修改权限
[root@mysql-server ~]# mkdir /var/log/sql-bin
[root@mysql-server ~]# chown mysql.mysql /var/log/sql-bin
[root@mysql-server ~]# systemctl restart mysqld

mysql> flush logs; #刷新binlog日志会截断产生新的日志文件
mysql> create table testdb.t3(id int); #创建一个表

根据位置恢复
找到要恢复的sql语句的起始位置、结束位置
[root@mysql-server sql-bin]# mysqlbinlog mylog.000002

测试
[root@mysql-server ~]# mysql -uroot -p'qf123'
mysql> drop table testdb.t3; #将这个表删除
Query OK, 0 rows affected (0.01 sec)
恢复:
[root@mysql-server ~]# cd /var/log/sql-bin/
[root@mysql-server sql-bin]# mysqlbinlog --start-position 219 --stop-position 321 mylog.000002 |mysql -uroot -p'qf123'
mysql: [Warning] Using a password on the command line interface can be insecure.
查看

网友评论