标签:date 字段 evel 回滚 工具 arch prim osc 操作
为保证没有其他参数配置影响,重新安装配置了一台最小化安装的CentOS7虚拟机
[root@localhost ~]# vi /etc/my.cnf
?修改mysql配置文件,在[mysqld]下增加以下内容
# 注释: 开启binlog 文件名以mysql-bin开头
log-bin = mysql-bin
# 注释: 备份恢复模式不需要开启Row模式 闪回需要开启Row模式
binlog_format=”ROW”
service mysqld restart
登录数据库 然后创建测试数据库demo和测试表user
mysql> create database demo;
Query OK, 1 row affected (0.00 sec)
mysql> use demo;
Database changed
mysql> CREATE TABLE user ( id int(8) NOT NULL AUTO_INCREMENT, name varchar(32) NOT NULL, type int(8) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB;
Query OK, 0 rows affected (0.01 sec)
?准备完毕,刷新掉binlog文件,此时binlog文件mysql-bin.000001结束,进入mysql-bin.000002记录
mysql> flush logs;
Query OK, 0 rows affected (0.00 sec)
[root@localhost ~]# mysqldump -u root -p –databases demo > db_demo_bak.sql
mysql> insert into user (id,name,type) value (10001,’A’,’1’);
Query OK, 1 row affected (0.00 sec)
mysql> insert into user (id,name,type) value (10002,’B’,’1’);
Query OK, 1 row affected (0.00 sec)
mysql> select * from user;
+——-+——+——+
| id | name | type |
+——-+——+——+
| 10001 | A | 1 |
| 10002 | B | 1 |
+——-+——+——+
2 rows in set (0.00 sec)
mysql> update user set name = ‘C’;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> select * from user;
+——-+——+——+
| id | name | type |
+——-+——+——+
| 10001 | C | 1 |
| 10002 | C | 1 |
+——-+——+——+
2 rows in set (0.00 sec)
mysql> flush logs;
Query OK, 0 rows affected (0.01 sec)
[root@localhost ~]# ls /var/lib/mysql
auto.cnf ibdata1 ib_logfile1 mysql-bin.000001 mysql-bin.000003 mysql.sock
demo ib_logfile0 mysql mysql-bin.000002 mysql-bin.index performance_schema?
mysql> user demo;
mysql> drop table user;
mysql> source /root/db_demo_bak.sql
mysql> select * from user;
Empty set (0.00 sec)
mysql> show binlog events in ‘mysql-bin.000002’;
+——————+—–+————-+———–+————-+—————————————+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+——————+—–+————-+———–+————-+—————————————+
| mysql-bin.000002 | 4 | Format_desc | 1 | 120 | Server ver: 5.6.39-log, Binlogver: 4 |
| mysql-bin.000002 | 120 | Query | 1 | 192 | BEGIN |
| mysql-bin.000002 | 192 | Table_map | 1 | 243 | table_id: 72 (demo.user) |
| mysql-bin.000002 | 243 | Write_rows | 1 | 289 | table_id: 72 flags: STMT_END_F |
| mysql-bin.000002 | 289 | Xid | 1 | 320 | COMMIT / xid=147 / |
| mysql-bin.000002 | 320 | Query | 1 | 392 | BEGIN |
| mysql-bin.000002 | 392 | Table_map | 1 | 443 | table_id: 72 (demo.user) |
| mysql-bin.000002 | 443 | Write_rows | 1 | 489 | table_id: 72 flags: STMT_END_F |
| mysql-bin.000002 | 489 | Xid | 1 | 520 | COMMIT / xid=148 / |
| mysql-bin.000002 | 520 | Query | 1 | 592 | BEGIN |
| mysql-bin.000002 | 592 | Table_map | 1 | 643 | table_id: 72 (demo.user) |
| mysql-bin.000002 | 643 | Update_rows | 1 | 723 | table_id: 72 flags: STMT_END_F|
| mysql-bin.000002 | 723 | Xid | 1 | 754 | COMMIT / xid=149 / |
| mysql-bin.000002 | 754 | Rotate | 1 | 801 | mysql-bin.000003;pos=4 |
+——————+—–+————-+———–+————-+—————————————+
14 rows in set (0.00 sec)
120 - 320 第一次insert
320 - 520 第二次insert
520 - 754 误操作update
[root@localhost ~]# mysqlbinlog –start-position=120 –stop-position=520 -database=demo /var/lib/mysql/mysql-bin.000003 | /usr/bin/mysql -u root -p mima666 -v demo
mysqlbinlog的详细使用方法参看官方文档 https://dev.mysql.com/doc
mysql> select * from user;
+——-+——+——+
| id | name | type |
+——-+——+——+
| 10001 | A | 1 |
| 10002 | B | 1 |
+——-+——+——+
2 rows in set (0.00 sec)
Ok,数据恢复成功
参考美团的开源项目MyFlash
MyFlash-gitee MyFlash-github
标签:date 字段 evel 回滚 工具 arch prim osc 操作
原文地址:https://www.cnblogs.com/sgmder/p/9331022.html