环境:Centos 7.5 + Mysql 8.0.19 + python3.8
先说说遇到的两个坑:
1、PyMySQL 使用的版本必须是0.9.3
binlog2sql 源码里 requirements.txt 指定的版本是0.7.11,后来尝试了最新版,最后翻了N偏帖子,有位兄弟说必须使用0.9.3,才得以解决
2、UnicodeDecodeError: 'utf-8' codec can't decode byte xxx 此类错误
将binlog2sql_util.py中的decode("utf-8")
替换为<code>decode("utf-8","ignore")
3、先检查是否有开启log_bin
python安装过程:
这里,我就准备安装一个 Python3.8 的版本,但是,我不准备覆盖原来的 Python2.7,也就是说,最终在我的系统中,会有两个 Python 的版本,互不干扰。
下载 Python3.8.1 源代码,python各个版本源码链接:https://www.python.org/ftp/python/
wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz
tar -zvxf Python-3.8.1.tgz &&cd Python-3.8.1/
安装依赖:
yum install -y wget zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc libffi-devel
yum --exclude=kernel* update -y
yum groupinstall -y 'Development Tools'
编译安装:
./configure prefix=/usr/local/python3 --enable-optimizations
make&&makeinstall
export PATH=$PATH:/usr/local/python3/bin/
binlog2sql安装过程:
Binlog2sql工具传送门:https://github.com/danfengcao/binlog2sql
yum install -y git
git clone https://github.com/danfengcao/binlog2sql.git && cd binlog2sql vi requirements.txt //修改pymysql版本成0.9.3如下图
python3 -m pip install -r requirements.txt
安装成功后查看:
测试数据:
新增了4条数据,随后删除表数据,操作时间大概为10:47
mysql版本为8.0.20
查看当前binlog文件
查看误删除操作SQL:
python3 binlog2sql.py -h127.0.0.1 -P10002 -uroot -ppassword -d test_db -t test_table --start-file='binlog.000013' --start-datetime='2020-08-17 10:47:00' --stop-datetime='2020-08-17 10:50:00'
解析SQL:
python3 binlog2sql.py -h127.0.0.1 -P10002 -uroot -ppassword -d test_db -t test_table --start-file='binlog.000013' --start-position=1804 --stop-position=2113 -B > rollback.sql
python3 binlog2sql.py --flashback -h127.0.0.1 -P10002 -uroot -ppassword -d test_db -t test_table --start-file='binlog.000013' --start-datetime='2020-08-17 10:47:00' --stop-datetime='2020-08-17 10:50:00' | cut -d '#' -f1 >undo.sql sed -i 's/addtime/vcol1/g' undo.sql sed -i 's/name/addtime/g' undo.sql sed -i 's/id/name/g' undo.sql sed -i 's/vcol1/id/g' undo.sql
共 0条评论
发表评论 请登录再评论