ITPub博客

首页 > 数据库 > MySQL > mysqlbinlog-flashback测试

mysqlbinlog-flashback测试

原创 MySQL 作者:jacobxian 时间:2015-01-19 01:13:54 0 删除 编辑
insert和delete操作都能闪回成功,但是update操作却没有任何效果,原因是下面sql的 where条件和set搞反,

mysqlbinlog
是从下面网址下来回来的raw文件。
https://github.com/wubx/mysql-binlog-statistic/blob/cc01e8e13e05ad82a2ff0be36ca8dd48f29fb347/bin/mysqlbinlog
源码文件在下面地址:
http://mysql.taobao.org/index.php/Patch_source_code#Add_flashback_feature_for_mysqlbinlog


插入测试数据:
create table t_insert_xyz(id int,name varchar(100));
insert into t_insert_xyz(id,name)values(1 ,'insert01');
insert into t_insert_xyz(id,name)values(2 ,'insert02');


create table t_delete_xyz(id int,name varchar(100));
insert into t_delete_xyz(id,name)values(1 ,'delete01');
insert into t_delete_xyz(id,name)values(2 ,'delete02');


select * from t_insert_xyz;
select * from t_delete_xyz;


mysql> select * from t_insert_xyz;
+------+----------+
| id   | name     |
+------+----------+
|    1 | insert01 |
|    2 | insert02 |
+------+----------+
2 rows in set (0.00 sec)


mysql> select * from t_delete_xyz;
+------+----------+
| id   | name     |
+------+----------+
|    1 | delete01 |
|    2 | delete02 |
+------+----------+
2 rows in set (0.00 sec)


mysql> set  global binlog_format=row;
mysql> set  binlog_format=row;
mysql> flush logs;
mysql> show master status;
+---------------+----------+--------------+------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| binlog.000013 |      107 |              |                  |
+---------------+----------+--------------+------------------+
1 row in set (0.00 sec)




insert into t_insert_xyz(id,name)values(3 ,'xyz03');


delete from t_delete_xyz where id=1;
commit;


mysql> select * from t_insert_xyz;
+------+----------+
| id   | name     |
+------+----------+
|    1 | insert01 |
|    2 | insert02 |
|    3 | xyz03    |
+------+----------+
3 rows in set (0.00 sec)




mysql> select * from t_delete_xyz;
+------+----------+
| id   | name     |
+------+----------+
|    2 | delete02 |
+------+----------+
1 row in set (0.00 sec)


mysql> show master status ;
+---------------+----------+--------------+------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| binlog.000013 |      500 |              |                  |
+---------------+----------+--------------+------------------+
1 row in set (0.00 sec)




mysql> select * from t_insert_xyz;
+------+----------+
| id   | name     |
+------+----------+
|    1 | insert01 |
|    2 | insert02 |
|    3 | xyz03    |
+------+----------+
3 rows in set (0.00 sec)


mysql> select * from t_delete_xyz;
+------+----------+
| id   | name     |
+------+----------+
|    2 | delete02 |
+------+----------+
1 row in set (0.00 sec)




检查输出结果,根据输出结果,dml操作是逆时针进行的。
mysqlbinlog -v --base64-output=decode-rows -B --start-position=107 --stop-position=716 /mysql/mysqllog/binlog/binlog.000013>B13.sql
实际执行恢复脚本和命令:
mysqlbinlog -B --start-position=107 --stop-position=500 /mysql/mysqllog/binlog/binlog.000013|mysql -uroot -ppassword test




mysql> select * from t_insert_xyz;
+------+----------+
| id   | name     |
+------+----------+
|    1 | insert01 |
|    2 | insert02 |
+------+----------+
2 rows in set (0.00 sec)


mysql> select * from t_delete_xyz;
+------+----------+
| id   | name     |
+------+----------+
|    2 | delete02 |
|    1 | delete01 |
+------+----------+
2 rows in set (0.00 sec)


insert和delete操作都能闪回成功,但是update操作却没有任何效果,原因是下面sql的 where条件和set搞反,
#150118  8:11:21 server id 3  end_log_pos 429   Table_map: `test`.`t_update_xyz` mapped to number 42
#150118  8:11:21 server id 3  end_log_pos 491   Update_rows: table id 42 flags: STMT_END_F
### UPDATE test.t_update_xyz
### WHERE
###   @1=1
###   @2='update_new'
### SET
###   @1=1
###   @2='update01'
#150118  8:11:21 server id 3  end_log_pos 375   Query   thread_id=6     exec_time=0     error_code=0


需要进行测试ddl在中间情况,是否可以进行恢复操作:
应该避免下面操作:
[mysql@mysql1 binlog]$ cat B9.sql |grep DROP
[mysql@mysql1 binlog]$ cat B9.sql |grep TRUNCATE
[mysql@mysql1 binlog]$ cat B9.sql |grep ALTER


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29114615/viewspace-1406317/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-07-16

  • 博文量
    18
  • 访问量
    45385