软件包下载地址:链接:https://pan.baidu.com/s/15dDeGufVWOgVrfATGWBzaA 密码:gnz8
DBA或开发人员,有时会误删或者误更新数据,如果是线上环境会影响较大,这就需要能快速回滚;而MySQL闪回(flashback)利用binlog能直接进行回滚,并且能快速恢复数据(MySQL闪回现在只支持DML语句进行闪回)。
利用binlog闪回需要的条件:
Mysql参数设置:
log_bin = /目录/mysql-bin.log(开启)
binlog_format = row
binlog_row_image = full(默认是full)
工作原理主要是对于delete操作,从binlog取出delete信息,生成insert的回滚语句。对于insert操作,回滚SQL是delete。对于update操作,回滚sql应该交换SET和WHERE的值。
安装:
环境准备安装各种依赖的工具包列表
将python换成python3.6版本 (python版本升级参考博客:https://blog.csdn.net/wwwdaan5com/article/details/78218277)
python-pip ,
PyMySQL ,
python-mysql-replication,
wheel argparse
1、binlog2sql下载
https://github.com/danfengcao/binlog2sql
2、binlog2sql依赖包安装
(1)PyMySQL-0.8.0安装
https://pypi.python.org/pypi/PyMySQL/
[[email protected] binlogsql]# tar -xzvf PyMySQL-0.8.0.tar.gz
[[email protected] binlogsql]# cd PyMySQL-0.8.0
[[email protected] PyMySQL-0.8.0]# python setup.py install
(2)wheel-0.31.0安装
https://pypi.python.org/pypi/wheel/
[[email protected] binlogsql]# tar -xzvf wheel-0.31.0.tar.gz
[[email protected] binlogsql]# cd wheel-0.31.0
[[email protected] wheel-0.31.0]# python setup.py install
(3)python-mysql-replication安装
https://github.com/noplay/python-mysql-replication
[[email protected] binlogsql]# unzip python-mysql-replication-master.zip
[[email protected] binlogsql]# cd python-mysql-replication-master
[[email protected] python-mysql-replication-master]# python setup.py install
(4)可以通过pip安装相应的依赖包
https://pypi.python.org/pypi/pip
[[email protected] tools]# tar -xzvf pip-10.0.1.tar.gz
[[email protected] tools]# cd pip-10.0.1
[[email protected] pip-10.0.1]# python setup.py install
[[email protected] binlog2sql-master]# pip install -r requirements.txt
可能会出错误。
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.6/site-packages/mysql_replication-0.18-py3.6.egg'
依赖包版本问题。
执行。。pip install mysql-replication
再执行 pip install -r requirements.txt
显示都已安装完成。
原文地址:http://blog.51cto.com/woniu123/2114547