博主介绍:
IT邦德,江湖人称jeames007,10年DBA工作经验
中国DBA联盟(ACDU)成员,目前从事DBA及程序编程
(Web\java\Python)工作,主要服务于生产制造
现拥有 Oracle 11g OCP/OCM、
Mysql、Oceanbase(OBCA)认证
分布式TBase\TDSQL数据库、国产达梦数据库以及红帽子认证
擅长主流数据Oracle、MySQL、PG 运维开发,备份恢复,
安装迁移,性能优化、故障应急处理等。
工具官网
https://github.com/danfengcao/binlog2sql
##安装git和pip依赖包
yum install -y git
yum install -y python3
##安装 binlog2sql 工具
git clone https://github.com/danfengcao/binlog2sql.git && cd binlog2sql
pip3 install -r requirements.txt
mysql> create database jem_db;
mysql> use jem_db
mysql> CREATE TABLE test1(id INT ,name varchar(30));
mysql> INSERT INTO test1 values(3,'aa'),(4,'bb');
mysql> delete from test1; --误删除了
mysql> show master status
#回滚SQL
python3 /root/binlog2sql/binlog2sql/binlog2sql.py -uroot -proot -djem_db -test1 --start-file=‘binlog.000004’ -B
官网:https://github.com/liuhr/my2sql
也可以直接下载编译好的二进制文件。
wget https://raw.githubusercontent.com/liuhr/my2sql/master/releases/my2sql
mv my2sql /usr/lolca/bin/my2sql
[root@binlog2sql ~]# mkdir /bk
mysql> flush logs; ##切日志
mysql> show master status;
mysql> show master logs; ##查看所有日志大小
CREATE DATABASE `testdb` charset utf8mb4;
use testdb;
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`number` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
`add_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加的时间',
`content` json DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_name` (`number`,`name`)
) ENGINE=InnoDB AUTO_INCREMENT=1234 DEFAULT CHARSET=utf8;
INSERT INTO `testdb`.`student` (`id`,`number`,`name`,`add_time`,`content`)
VALUES (1233,26,'ranran','2020-07-15 19:06:03',null);
INSERT INTO `testdb`.`student` (`id`,`number`,`name`,`add_time`,`content`)
VALUES (1232,134,'asdf','2020-07-12 11:08:41',null);
-- 回滚 sql
##确定好启始和结束的位置
my2sql -user root -password root -host 192.168.39.232 -port 3308
-databases testdb -work-type 2sql -start-file binlog.000037 -start-pos 156
-stop-file binlog.000037 -stop-pos 5205 -output-dir /bk
官网下载:
https://github.com/Meituan-Dianping/MyFlash
yum -y install git
yum install gcc* pkg-config glib2 libgnomeui-devel -y
git clone https://github.com/Meituan-Dianping/MyFlash.git
cd MyFlash/
gcc -w `pkg-config --cflags --libs glib-2.0` source/binlogParseGlib.c -o binary/flashback
cd binary
./flashback --help
Usage:
flashback [OPTION...]
Help Options:
-?, --help Show help options
Application Options:
--databaseNames databaseName to apply. if multiple, seperate by comma(,)
--tableNames tableName to apply. if multiple, seperate by comma(,)
--start-position start position
--stop-position stop position
--start-datetime start time (format %Y-%m-%d %H:%M:%S)
--stop-datetime stop time (format %Y-%m-%d %H:%M:%S)
--sqlTypes sql type to filter . support INSERT, UPDATE ,DELETE. if multiple, seperate by comma(,)
--maxSplitSize max file size after split, the uint is M
--binlogFileNames binlog files to process. if multiple, seperate by comma(,)
--outBinlogFileNameBase output binlog file name base
--logLevel log level, available option is debug,warning,error
--include-gtids gtids to process
--exclude-gtids gtids to skip
大家点赞、收藏、关注、评论啦 微信公众号