binlog2sql闪回工具的使用

binlog2sql闪回工具的使用

一、下载安装依赖的python

yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
yum install python34 -y
python3 --version
wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
pip3 -V

切换升级本地python版本

python -V; python2.6 -V
# 查看当前python版本 这两个应该都是原始的2.6.x
ls -hli /usr/bin/python*
cp -f /usr/bin/python2.6 /usr/bin/python2.6.bak
rm -f /usr/bin/python /usr/bin/python
cp /usr/bin/python3.4 /usr/bin/python
ls -hli /usr/bin/python*
python -V; python2.6 -V
# 验证python版本是否OK(python->2.7, python2.6->python2.6.x)

yum -h # 验证yum已经不可用,命令会出错退出
head -n 2 /usr/bin/yum
sed -i ‘s/python$/&2\.6/‘ /usr/bin/yum
head -n 2 /usr/bin/yum
# 将/usr/bin/yum 中的python 替换为python2.6
yum -h # 验证yum可用,此时不会再出错退出

二、安装binlog2sql

# 参考资料:https://www.runoob.com/w3cnote/python-pip-install-usage.html
cd /opt/
yum -y install  python-pip
git clone https://github.com/danfengcao/binlog2sql.git && cd binlog2sql
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

查看帮助

[[email protected]_test_002 binlog2sql]# /usr/bin/python /opt/binlog2sql/binlog2sql/binlog2sql.py --help
usage: binlog2sql.py [-h HOST] [-u USER] [-p [PASSWORD [PASSWORD ...]]]
                     [-P PORT] [--start-file START_FILE]
                     [--start-position START_POS] [--stop-file END_FILE]
                     [--stop-position END_POS] [--start-datetime START_TIME]
                     [--stop-datetime STOP_TIME] [--stop-never] [--help]
                     [-d [DATABASES [DATABASES ...]]]
                     [-t [TABLES [TABLES ...]]] [--only-dml]
                     [--sql-type [SQL_TYPE [SQL_TYPE ...]]] [-K] [-B]
                     [--back-interval BACK_INTERVAL]

Parse MySQL binlog to SQL you want

optional arguments:
  --stop-never          Continuously parse binlog. default: stop at the latest
                        event when you start.
  --help                help information
  -K, --no-primary-key  Generate insert sql without primary key if exists
  -B, --flashback       Flashback data to start_position of start_file
  --back-interval BACK_INTERVAL
                        Sleep time between chunks of 1000 rollback sql. set it
                        to 0 if do not need sleep

connect setting:
  -h HOST, --host HOST  Host the MySQL database server located
  -u USER, --user USER  MySQL Username to log in as
  -p [PASSWORD [PASSWORD ...]], --password [PASSWORD [PASSWORD ...]]
                        MySQL Password to use
  -P PORT, --port PORT  MySQL port to use

interval filter:
  --start-file START_FILE
                        Start binlog file to be parsed
  --start-position START_POS, --start-pos START_POS
                        Start position of the --start-file
  --stop-file END_FILE, --end-file END_FILE
                        Stop binlog file to be parsed. default: ‘--start-file‘
  --stop-position END_POS, --end-pos END_POS
                        Stop position. default: latest position of ‘--stop-
                        file‘
  --start-datetime START_TIME
                        Start time. format %Y-%m-%d %H:%M:%S
  --stop-datetime STOP_TIME
                        Stop Time. format %Y-%m-%d %H:%M:%S;

schema filter:
  -d [DATABASES [DATABASES ...]], --databases [DATABASES [DATABASES ...]]
                        dbs you want to process
  -t [TABLES [TABLES ...]], --tables [TABLES [TABLES ...]]
                        tables you want to process

type filter:
  --only-dml            only print dml, ignore ddl
  --sql-type [SQL_TYPE [SQL_TYPE ...]]
                        Sql type you want to process, support INSERT, UPDATE,
                        DELETE.
[[email protected]_test_002 binlog2sql]# 

三、使用该工具的前提

1. binlog_format为ROW,且binlog_row_image为full或noblog,默认为full。

2. 必须开启MySQL Server,理由有如下两点:

1> 它是基于BINLOG_DUMP协议来获取binlog内容

2> 需要读取server端information_schema.COLUMNS表,获取表结构的元信息,拼接成可视化的sql语句

该工具所需权限如下:

mysql> GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO ‘flashbak_user‘@‘%‘ identified by ‘flashbak_user_pwd‘;

**权限说明**

* select:需要读取server端information_schema.COLUMNS表,获取表结构的元信息,拼接成可视化的sql语句
* super/replication client:两个权限都可以,需要执行‘SHOW MASTER STATUS‘, 获取server端的binlog列表
* replication slave:通过BINLOG_DUMP协议获取binlog内容的权限

因为是伪装成slave来获取主的二进制事件,故无需对binlog有可读权限。

四、测试验证

4-1、创建测试表

# 创建测试表
CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;

insert into user(name) values(‘小赵‘);
insert into user(name) values(‘小王‘);
insert into user(name) values(‘小李‘);
insert into user(name) values(‘小钱‘);
insert into user(name) values(‘小孙‘);

mysql> select * from user;
+----+--------+
| id | name   |
+----+--------+
|  6 | 小赵   |
|  7 | 小王   |
|  8 | 小李   |
|  9 | 小钱   |
| 10 | 小孙   |
+----+--------+
5 rows in set (0.00 sec)

4-2、update回滚实践

# update误操作闪回
mysql> update user set name=‘王源‘ where id=8;
Query OK, 1 row affected (0.07 sec)
Rows matched: 1  Changed: 1  Warnings: 0

#发现修改错了。
[[email protected]_test_001 binlogdir]$ /data/mysql/percona_server/bin/mysqlbinlog --no-defaults --base64-output=decode-rows -vvv mysql-bin.000024 >./24.binlog
# 搜索到王源,找到position点:--startposition=2082 --stop-position=2268

# 先解析出原始语句,以便确认
# 主库IP: 10.10.50.60 用户名:flashbak_user 密码:flashbak_user_pwd
/usr/bin/python /opt/binlog2sql/binlog2sql/binlog2sql.py  -h 10.10.50.60 -P3306 -uflashbak_user -pflashbak_user_pwd -dsbtest -tuser --start-file=‘mysql-bin.000024‘ --stop-file=‘mysql-bin.000024‘ 

[[email protected]_test_002 binlog2sql]# /usr/bin/python /opt/binlog2sql/binlog2sql/binlog2sql.py  -h 10.10.50.60 -P3306 -uflashbak_user -pflashbak_user_pwd -dsbtest -tuser --start-file=‘mysql-bin.000024‘ --stop-file=‘mysql-bin.000024‘
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO ‘flashbak_user‘@‘%‘ IDENTIFIED BY PASSWORD ‘*0589CD47DC016BC67FC7720BADEC3C1368C15F60‘;
USE b‘sbtest‘;
CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (6, ‘小赵‘); #start 822 end 995 time 2019-12-23 10:38:40
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (7, ‘小王‘); #start 1074 end 1247 time 2019-12-23 10:38:40
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (8, ‘小李‘); #start 1326 end 1499 time 2019-12-23 10:38:40
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (9, ‘小钱‘); #start 1578 end 1751 time 2019-12-23 10:38:40
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (10, ‘小孙‘); #start 1830 end 2003 time 2019-12-23 10:38:41
UPDATE `sbtest`.`user` SET `id`=8, `name`=‘王源‘ WHERE `id`=8 AND `name`=‘小李‘ LIMIT 1; #start 2082 end 2268 time 2019-12-23 10:41:20
[[email protected]_test_002 binlog2sql]# 

# 进一步筛选
/usr/bin/python /opt/binlog2sql/binlog2sql/binlog2sql.py  -h 10.10.50.60 -P3306 -uflashbak_user -pflashbak_user_pwd -dsbtest -tuser --start-file=‘mysql-bin.000024‘ --stop-file=‘mysql-bin.000024‘ --sql-type=UPDATE --start-position=2082 --stop-position=2268
[[email protected]_test_002 binlog2sql]# /usr/bin/python /opt/binlog2sql/binlog2sql/binlog2sql.py  -h 10.10.50.60 -P3306 -uflashbak_user -pflashbak_user_pwd -dsbtest -tuser --start-file=‘mysql-bin.000024‘ --stop-file=‘mysql-bin.000024‘ --sql-type=UPDATE --start-position=2082 --stop-position=2268
UPDATE `sbtest`.`user` SET `id`=8, `name`=‘王源‘ WHERE `id`=8 AND `name`=‘小李‘ LIMIT 1; #start 2082 end 2268 time 2019-12-23 10:41:20
[[email protected]_test_002 binlog2sql]# 

# 生成回滚语句
[[email protected]_test_002 binlog2sql]# /usr/bin/python /opt/binlog2sql/binlog2sql/binlog2sql.py -B -h 10.10.50.60 -P3306 -uflashbak_user -pflashbak_user_pwd -dsbtest -tuser --start-file=‘mysql-bin.000024‘ --stop-file=‘mysql-bin.000024‘ --sql-type=UPDATE --start-position=2082 --stop-position=2268
UPDATE `sbtest`.`user` SET `id`=8, `name`=‘小李‘ WHERE `id`=8 AND `name`=‘王源‘ LIMIT 1; #start 2082 end 2268 time 2019-12-23 10:41:20
[[email protected]_test_002 binlog2sql]# 

mysql> select * from user;
+----+--------+
| id | name   |
+----+--------+
|  6 | 小赵   |
|  7 | 小王   |
|  8 | 王源   |
|  9 | 小钱   |
| 10 | 小孙   |
+----+--------+
5 rows in set (0.00 sec)

mysql> UPDATE `sbtest`.`user` SET `id`=8, `name`=‘小李‘ WHERE `id`=8 AND `name`=‘王源‘ LIMIT 1; #start 2082 end 2268 time 2019-12-23 10:41:20
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from user;
+----+--------+
| id | name   |
+----+--------+
|  6 | 小赵   |
|  7 | 小王   |
|  8 | 小李   |
|  9 | 小钱   |
| 10 | 小孙   |
+----+--------+
5 rows in set (0.00 sec)

mysql> 

4-3、delete操作回滚实践

# delete语句回滚
mysql> delete from user where id in (6,8,9,10);
Query OK, 4 rows affected (0.01 sec)

mysql> select * from user;
+----+--------+
| id | name   |
+----+--------+
|  7 | 小王   |
+----+--------+
1 row in set (0.00 sec)

[[email protected]_test_002 binlog2sql]# /usr/bin/python /opt/binlog2sql/binlog2sql/binlog2sql.py -h 10.10.50.60 -P3306 -uflashbak_user -pflashbak_user_pwd -dsbtest -tuser --start-file=‘mysql-bin.000024‘ --stop-file=‘mysql-bin.000024‘ --sql-type=‘DELETE‘
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO ‘flashbak_user‘@‘%‘ IDENTIFIED BY PASSWORD ‘*0589CD47DC016BC67FC7720BADEC3C1368C15F60‘;
USE b‘sbtest‘;
CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
DELETE FROM `sbtest`.`user` WHERE `name`=‘小赵‘ AND `id`=6 LIMIT 1; #start 2612 end 2821 time 2019-12-23 11:03:34
DELETE FROM `sbtest`.`user` WHERE `name`=‘小李‘ AND `id`=8 LIMIT 1; #start 2612 end 2821 time 2019-12-23 11:03:34
DELETE FROM `sbtest`.`user` WHERE `name`=‘小钱‘ AND `id`=9 LIMIT 1; #start 2612 end 2821 time 2019-12-23 11:03:34
DELETE FROM `sbtest`.`user` WHERE `name`=‘小孙‘ AND `id`=10 LIMIT 1; #start 2612 end 2821 time 2019-12-23 11:03:34

# 生成delete的回滚语句
[[email protected]_test_002 binlog2sql]# /usr/bin/python /opt/binlog2sql/binlog2sql/binlog2sql.py -B -h 10.10.50.60 -P3306 -uflashbak_user -pflashbak_user_pwd -dsbtest -tuser --start-file=‘mysql-bin.000024‘ --stop-file=‘mysql-bin.000024‘ --sql-type=‘DELETE‘ --start-position=2612 --stop-position=2821
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (10, ‘小孙‘); #start 2612 end 2821 time 2019-12-23 11:03:34
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (9, ‘小钱‘); #start 2612 end 2821 time 2019-12-23 11:03:34
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (8, ‘小李‘); #start 2612 end 2821 time 2019-12-23 11:03:34
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (6, ‘小赵‘); #start 2612 end 2821 time 2019-12-23 11:03:34
[[email protected]_test_002 binlog2sql]# 

# 应用回滚
mysql>  INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (10, ‘小孙‘); #start 2612 end 2821 time 2019-12-23 11:03:34
Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (9, ‘小钱‘); #start 2612 end 2821 time 2019-12-23 11:03:34
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (8, ‘小李‘); #start 2612 end 2821 time 2019-12-23 11:03:34
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (6, ‘小赵‘); #start 2612 end 2821 time 2019-12-23 11:03:34
Query OK, 1 row affected (0.00 sec)

mysql> select * from user;
+----+--------+
| id | name   |
+----+--------+
|  6 | 小赵   |
|  7 | 小王   |
|  8 | 小李   |
|  9 | 小钱   |
| 10 | 小孙   |
+----+--------+
5 rows in set (0.00 sec)

mysql> 

4-4、insert操作回滚实践

# insert语句回滚
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (1, ‘小赵x‘);
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (2, ‘小赵x‘);
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (3, ‘小赵x‘);
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (5, ‘小赵x‘);

[[email protected]_test_002 binlog2sql]# /usr/bin/python /opt/binlog2sql/binlog2sql/binlog2sql.py -h 10.10.50.60 -P3306 -uflashbak_user -pflashbak_user_pwd -dsbtest -tuser --start-file=‘mysql-bin.000024‘ --stop-file=‘mysql-bin.000024‘ --sql-type=‘INSERT‘
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO ‘flashbak_user‘@‘%‘ IDENTIFIED BY PASSWORD ‘*0589CD47DC016BC67FC7720BADEC3C1368C15F60‘;
USE b‘sbtest‘;
CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (6, ‘小赵‘); #start 822 end 995 time 2019-12-23 10:38:40
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (7, ‘小王‘); #start 1074 end 1247 time 2019-12-23 10:38:40
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (8, ‘小李‘); #start 1326 end 1499 time 2019-12-23 10:38:40
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (9, ‘小钱‘); #start 1578 end 1751 time 2019-12-23 10:38:40
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (10, ‘小孙‘); #start 1830 end 2003 time 2019-12-23 10:38:41
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (10, ‘小孙‘); #start 2900 end 3073 time 2019-12-23 11:13:28
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (9, ‘小钱‘); #start 3152 end 3325 time 2019-12-23 11:13:28
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (8, ‘小李‘); #start 3404 end 3577 time 2019-12-23 11:13:28
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (6, ‘小赵‘); #start 3656 end 3829 time 2019-12-23 11:13:30
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (1, ‘小赵x‘); #start 3908 end 4082 time 2019-12-23 11:19:55
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (2, ‘小赵x‘); #start 4161 end 4335 time 2019-12-23 11:19:55
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (3, ‘小赵x‘); #start 4414 end 4588 time 2019-12-23 11:19:55
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (5, ‘小赵x‘); #start 4667 end 4841 time 2019-12-23 11:19:56
[[email protected]_test_002 binlog2sql]# /usr/bin/python /opt/binlog2sql/binlog2sql/binlog2sql.py -h 10.10.50.60 -P3306 -uflashbak_user -pflashbak_user_pwd -dsbtest -tuser --start-file=‘mysql-bin.000024‘ --stop-file=‘mysql-bin.000024‘ --sql-type=‘INSERT‘ --start-position=3908 --stop-position=4841
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (1, ‘小赵x‘); #start 3908 end 4082 time 2019-12-23 11:19:55
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (2, ‘小赵x‘); #start 4161 end 4335 time 2019-12-23 11:19:55
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (3, ‘小赵x‘); #start 4414 end 4588 time 2019-12-23 11:19:55
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (5, ‘小赵x‘); #start 4667 end 4841 time 2019-12-23 11:19:56
[[email protected]_test_002 binlog2sql]# /usr/bin/python /opt/binlog2sql/binlog2sql/binlog2sql.py -B  -h 10.10.50.60 -P3306 -uflashbak_user -pflashbak_user_pwd -dsbtest -tuser --start-file=‘mysql-bin.000024‘ --stop-file=‘mysql-bin.000024‘ --sql-type=‘INSERT‘ --start-position=3908 --stop-position=4841
DELETE FROM `sbtest`.`user` WHERE `id`=5 AND `name`=‘小赵x‘ LIMIT 1; #start 4667 end 4841 time 2019-12-23 11:19:56
DELETE FROM `sbtest`.`user` WHERE `id`=3 AND `name`=‘小赵x‘ LIMIT 1; #start 4414 end 4588 time 2019-12-23 11:19:55
DELETE FROM `sbtest`.`user` WHERE `id`=2 AND `name`=‘小赵x‘ LIMIT 1; #start 4161 end 4335 time 2019-12-23 11:19:55
DELETE FROM `sbtest`.`user` WHERE `id`=1 AND `name`=‘小赵x‘ LIMIT 1; #start 3908 end 4082 time 2019-12-23 11:19:55
[[email protected]_test_002 binlog2sql]# 

# 应用回滚语句
mysql> INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (1, ‘小赵x‘);
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (2, ‘小赵x‘);
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (3, ‘小赵x‘);
INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (5, ‘小赵x‘);Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO `sbtest`.`user`(`id`, `name`) VALUES (5, ‘小赵x‘);
Query OK, 1 row affected (0.00 sec)

mysql> select * from user;
+----+---------+
| id | name    |
+----+---------+
|  1 | 小赵x   |
|  2 | 小赵x   |
|  3 | 小赵x   |
|  5 | 小赵x   |
|  6 | 小赵    |
|  7 | 小王    |
|  8 | 小李    |
|  9 | 小钱    |
| 10 | 小孙    |
+----+---------+
9 rows in set (0.00 sec)

mysql> DELETE FROM `sbtest`.`user` WHERE `id`=5 AND `name`=‘小赵x‘ LIMIT 1; #start 4667 end 4841 time 2019-12-23 11:19:56
DELETE FROM `sbtest`.`user` WHERE `id`=3 AND `name`=‘小赵x‘ LIMIT 1; #start 4414 end 4588 time 2019-12-23 11:19:55
Query OK, 1 row affected (0.00 sec)

mysql> DELETE FROM `sbtest`.`user` WHERE `id`=3 AND `name`=‘小赵x‘ LIMIT 1; #start 4414 end 4588 time 2019-12-23 11:19:55
DELETE FROM `sbtest`.`user` WHERE `id`=2 AND `name`=‘小赵x‘ LIMIT 1; #start 4161 end 4335 time 2019-12-23 11:19:55
Query OK, 1 row affected (0.01 sec)

mysql> DELETE FROM `sbtest`.`user` WHERE `id`=2 AND `name`=‘小赵x‘ LIMIT 1; #start 4161 end 4335 time 2019-12-23 11:19:55
Query OK, 1 row affected (0.01 sec)

mysql> DELETE FROM `sbtest`.`user` WHERE `id`=1 AND `name`=‘小赵x‘ LIMIT 1; #start 3908 end 4082 time 2019-12-23 11:19:55
Query OK, 1 row affected (0.01 sec)

mysql> select * from user;
+----+--------+
| id | name   |
+----+--------+
|  6 | 小赵   |
|  7 | 小王   |
|  8 | 小李   |
|  9 | 小钱   |
| 10 | 小孙   |
+----+--------+
5 rows in set (0.00 sec)

mysql> 

附录:

# binlog2sql参数
[[email protected]_test_002 binlog2sql]# /usr/bin/python /opt/binlog2sql/binlog2sql/binlog2sql.py --help
  File "/opt/binlog2sql/binlog2sql/binlog2sql.py", line 73
    with temp_open(tmp_file, "w") as f_tmp, self.connection as cursor:
                                          ^
SyntaxError: invalid syntax
[[email protected]_test_002 binlog2sql]# 

# 出现上述提示,请更换python版本即可,不要使用python2.6版本

原文地址:https://www.cnblogs.com/bjx2020/p/12028681.html

时间: 2024-11-12 02:53:31

binlog2sql闪回工具的使用的相关文章

Mysql闪回工具之binlog2sql的原理及其使用

生产上误删数据.误改数据的现象也是时常发生的现象,作为运维这时候就需要出来补锅了,最开始的做法是恢复备份,然后从中找到需要的数据再进行修复,但是这个时间太长了,对于大表少数数据的修复来讲,动作太大,成本也大. 当然还有其他的一些操作方法,我们今天有主角. MySQL 闪回工具 --   binlog2sql 用途 数据回滚 主从切换后数据不一致的修复 从 binlog 生成标准 SQL,带来的衍生功能 闪回原理简析 开始之前,先说说闪回.我们都知道 MySQL binlog 以 event 为单

mysql闪回工具binlog2sql 安装使用

软件包下载地址:链接:https://pan.baidu.com/s/15dDeGufVWOgVrfATGWBzaA 密码:gnz8 DBA或开发人员,有时会误删或者误更新数据,如果是线上环境会影响较大,这就需要能快速回滚;而MySQL闪回(flashback)利用binlog能直接进行回滚,并且能快速恢复数据(MySQL闪回现在只支持DML语句进行闪回). 利用binlog闪回需要的条件: Mysql参数设置: log_bin = /目录/mysql-bin.log(开启) binlog_fo

binlog2sql闪回恢复数据

用途: 1.数据快速回滚 2.从binlog生成标准sql 使用限制: 1.必须设置binlog_format=ROW 2.binlog_row_image=full,该参数默认为FULL 3.恢复用户拥有的最小权限集合为:select, super/replication client, replication slave 建议授权 GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 权限说明 select:需要读取ser

MyFlash MySQL闪回工具

安装:环境要求:1.binlog格式必须为row,且binlog_row_image=full2.仅支持5.6与5.73.只能回滚DML(增.删.改) 下载地址:https://github.com/Meituan-Dianping/MyFlash 安装:unzip MyFlash-master.zipmv MyFlash-master /usr/local/MyFlash/gcc -w pkg-config --cflags --libs glib-2.0 source/binlogParse

MySQL 闪回工具MyFlash

一. 简介 背景:由于运维.开发误操作或是业务bug,我们在操作中时不时会出现误删除数据情况.早期要想恢复数据,只能让业务人员根据线上操作日志,构造误删除的数据,或者DBA使用binlog和备份的方式恢复数据,不管那种,都非常费时费力,而且容易出错. MyFlash是由美团点评公司技术工程部开发维护的一个回滚DML操作的工具.该工具通过解析v4版本的binlog,完成回滚操作.相对已有的回滚工具,其增加了更多的过滤选项,让回滚更加容易. 二. 恢复工具对比 1.mysqlbinlog工具配合se

binlog2sql之MySQL数据闪回

DBA或开发人员,有时会误删或者误更新数据,如果是线上环境并且影响较大,就需要能快速回滚.传统恢复方法是利用备份重搭实例,再应用去除错误sql后的binlog来恢复数据.此法费时费力,甚至需要停机维护,并不适合快速回滚.也有团队利用LVM快照来缩短恢复时间,但快照的缺点是会影响mysql的性能.现在有不少好用而且效率又高的开源闪回工具如binlog2sql.mysqlbinlog_flashback,这些工具在工作中给DBA减轻了不少痛苦,以下针对binlog2sql的使用进行实践演练. bin

binlog2sql快速闪回

一.说明: DML(data manipulation language):       它们是SELECT.UPDATE.INSERT.DELETE,就象它的名字一样,这4条命令是用来对数据库里的数据进行操作的语言DDL(data definition language):       DDL比DML要多,主要的命令有CREATE.ALTER.DROP等,DDL主要是用在定义或改变表(TABLE)的结构,数据类型,表之间的链接和约束等初始化工作上,他们大多在建立表时使用DCL(Data Con

MySQL--------基于binlog实现闪回最佳实战

1. 背景 * 为了数据安全,搭建了主从.实时主从备份只能防止硬件问题,比如主库的硬盘损坏.但对于误操作,则无能为力.比如在主库误删一张表,或者一个update语句没有指定where条件,导致全表被更新.当操作被同步到从库上后,则主从都"回天无力". * 闪回用于快速恢复由于误操作丢失的数据.在DBA误操作时,可以把数据库恢复到以前某个时间点(或者说某个binlog的某个pos).比如忘了带where条件的update.delete操作,传统的恢复方式是利用全备+二进制日志前滚进行恢复

(4.11)mysql备份还原——mysql闪回技术(基于binlog)

0.闪回技术与工具简介 mysql闪回工具比较流行三大类: [0.1]官方的mysqlbinlog:支持数据库在线/离线,用脚本处理binlog的输出,转化成对应SQL再执行.通用性不好,对正则.sed等需要较高熟练度. [0.2]第三方的mysqlbinlog工具,比官方的工具多了一个闪回功能 -B [0.3]开源的binlog2sql:兼容性比较好,使用难度小,使用简单,前提是mysql必须开启. 最佳实践:线上使用binlog2sql,线下用mysqlbinlog以及mysqlbinlog