用bin2sql闪回mysql数据

2019-11-28  本文已影响0人  君子愁

bin2sql安装

已测试环境

Python 2.7, 3.4+

MySQL 5.6, 5.7

我在centos6.9安装得,默认python2.6,不符合要求,需要安装一个3.4.4得版本才行

python3.4.4下载: https://www.python.org/downloads/source/

mysql我用的是5.7的,符合要求


python3.4.4安装

cd /data/Python-3.4.4

./configure   --prefix=/usr/local/python3

make

make install

python3+以上的,自带了pip,所以不需要自己另外安装pip了

pip地址:/usr/local/python3/bin/pip3

bin2sql除了需要依赖pip,还需要依赖PyMySQL ,python-mysql-replication,wheel argparse

yum -y install epel-release   #安装epel源

yum -y install git    #安装git

cd /data

git clone https://github.com/danfengcao/binlog2sql.git && cd binlog2sql   #通过git拉取bin2sql源码包

/usr/local/python3/bin/pip3 install -r requirements.txt   #pip来安装  PyMySQL ,python-mysql-replication,wheel argparse和安装bin2sql


开始进行闪回

在主slave上创建一个用户,用于闪回

GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO  chen@'%' identified by '123456';

从一个binlog文件解析出标准的SQL语句

cd /data/binlog2sql/binlog2sql

/usr/local/python3/bin/pip3   binlog2sql.py -h127.0.0.1 -P3306 -uchen -p'123456'-dmei -t student --start-file='mysql-bin.000002'   #就会获取到mysql-bin.000002这个binlog文件的里面所有执行过的sql

获取闪回语句

cd /data/binlog2sql/binlog2sql

/usr/local/python3/bin/pip3  

binlog2sql.py --flashback -h127.0.0.1 -P3306 -uchen -p'123456'-dmei -t student

--start-file='mysql-bin.000002'    >/data/20191128.sql

闪回:

/usr/local/mysql/bin/mysql -uroot -p123456 mei < /data/20191128.sql


bin2sql官网:https://github.com/danfengcao/binlog2sql

python3.4.4下载: https://www.python.org/downloads/source/

上一篇下一篇

猜你喜欢

热点阅读