温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用mysqlbinlog_flashback工具的详细步骤

发布时间:2020-05-19 14:26:51 来源:网络 阅读:327 作者:三月 栏目:MySQL数据库

下文主要给大家带来使用mysqlbinlog_flashback工具的详细步骤,希望这些内容能够带给大家实际用处,这也是我编辑使用mysqlbinlog_flashback工具的详细步骤这篇文章的主要目的。好了,废话不多说,大家直接看下文吧。

一、下载安装

# wget https://github.com/58daojia-dba/mysqlbinlog_flashback/archive/master.zip

工具相关使用参数:

[root@ops-db-test01 mysqlbinlog_flashback-master]# python mysqlbinlog_back.py --help
===log will also  write to .//mysqlbinlog_flashback.log===
Usage: python mysqlbinlog_back.py [options]
sample1:python  mysqlbinlog_back.py --host="127.0.0.1" --username="root" --port=43306 --password="" --schema=test --table="test5"
sample2:python mysqlbinlog_back.py --host="127.0.0.1" --username="root" --port=43306 --password="" --schema=test --table="test5,test6" --binlog_end_time="2016-11-05 11:27:13" --binlog_start_file_name="mysql-bin.000024"  --binlog_start_file_position=4 --binlog_start_time="2016-11-04 11:27:13"  --skip_delete  --skip_insert --add_schema_name
sample3:python mysqlbinlog_back.py  --host="127.0.0.1" --username="root" --port=43306 --password="" --schema=test --table="test5,test6" --binlog_start_file_name="mysql-bin.000022"

Options:
  -h, --help            show this help message and exit
  -H HOST, --host=HOST  mandatory,mysql hostname
  -P PORT, --port=PORT  mysql port,default 3306
  -u USERNAME, --username=USERNAME
                        mandatory,username
  -p PASSWORD, --password=PASSWORD
                        password
  -s SCHEMA, --schema=SCHEMA
                        mandatory,mysql schema
  -t TABLES, --tables=TABLES
                        mandatory,mysql tables,suport multiple tables,use
                        comma as separator
  -N BINLOG_END_TIME, --binlog_end_time=BINLOG_END_TIME
                        binlog end time,format yyyy-mm-dd hh34:mi:ss,default
                        is current time
  -S BINLOG_START_FILE_NAME, --binlog_start_file_name=BINLOG_START_FILE_NAME
                        binlog start file name,default is current logfile of
                        db
  -L BINLOG_START_FILE_POSITION, --binlog_start_file_position=BINLOG_START_FILE_POSITION
                        binlog start file name
  -E BINLOG_START_TIME, --binlog_start_time=BINLOG_START_TIME
                        binlog start time,format yyyy-mm-dd hh34:mi:ss
  -l OUTPUT_FILE_PATH, --output_file_path=OUTPUT_FILE_PATH
                        file path that sql generated,,default ./log
  -I, --skip_insert     skip insert(WriteRowsEvent) event
  -U, --skip_update     skip update(UpdateRowsEvent) event
  -D, --skip_delete     skip delete(DeleteRowsEvent) event
  -a, --add_schema_name
                        add schema name for flashback sql
  -v, --version         version info

二、模拟误操作情况

1、批量删除操作

delete未加where条件,全表删除,此时表还有写入操作。

# python mysqlbinlog_back.py  --host="localhost" --username="" --port=3306 --password="" --schema=cy --table="obd_wave" --binlog_start_file_name="mysqlbinlog.000002" --binlog_start_time="2017-08-02 20:10:00"

log目录下生成三个文件

# ll -sh
13M -rw-r--r-- 1 root root  13M Aug  2 20:38 flashback_cy_20170802_203747.sql    //反向sql
4.0K -rw-r--r-- 1 root root 2.6K Aug  2 20:38 save_data_create_table_cy_20170802_203747.sql
 29M -rw-r--r-- 1 root root  29M Aug  2 20:38 save_data_dml_cy_20170802_203747.sql

找到删除开始和结束的位置。

 执行命令

# python mysqlbinlog_back.py  --host="localhost" --username="" --port=3306 --password="" --schema=cy --table="obd_wave" --binlog_start_file_name="mysqlbinlog.000002" --binlog_start_time="2017-08-02 20:10:00" --binlog_start_file_position=9664085

手动删除,误操作之后的反向sql的内容。

    --缺点:只能指定开始的位置,不能指定结束的位置及时间。

对于以上关于使用mysqlbinlog_flashback工具的详细步骤,大家是不是觉得非常有帮助。如果需要了解更多内容,请继续关注我们的行业资讯,相信你会喜欢上这些内容的。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI