mysql数据回滚恢复通过binlog2sql解决MySQL8,编码问题

mysql数据回滚恢复通过binlog2sql解决MySQL8,编码问题

一、产生原因

由于在MySQL命令框中输入删除命令是条件写错,导致误删除了几条于别的表关联的数据,由于关联的是随机生成的id,为了保证数据一致和关联性,进行数据库binlog回滚数据

  1. 通过mysqlbinlog命令进行恢复生成的sql文件无法执行总是存在编码问题,解决起来相对麻烦耗时
  2. 使用线程的binlog2sql进行数据回闪生成sql执行
    2.1 安装Python
    2.2 安装binlog2sql
    git clone https://github.com/danfengcao/binlog2sql.git //下载binlog2sql
    pip install -r requirements.txt
    2.3 在binbog2sql.py 目录下执行生成回滚sql操作
    C:\software\binlog2sql\binlog2sql>python binlog2sql.py -hlocalhost -P3306 -uroot -d jeecg-boot -t tr_user --start-datetime “2021-07-23 16:00:00” -B --start-file=CY016593-bin.000005 > a.sql

    关于该工具的使用方法可参考github操作文档:https://github.com/danfengcao/binlog2sql

遇到的问题

  1. Traceback (most recent call last):
    File “binlog2sql.py”, line 149, in
    back_interval=args.back_interval, only_dml=args.only_dml, sql_type=args.sql_type)
    File “binlog2sql.py”, line 46, in init
    self.connection = pymysql.connect(**self.conn_setting)
  2. 解决问题1后产生的问题2
    UnicodeDecodeError: ‘utf-8’ codec can’t decode byte xxx

二、解决办法

问题1 mysql8的版本问题,安装对应的binlog2sql工具版本

pip uninstall PyMySQL
pip install PyMySQL==0.9.3

问题2 编码问题
将binlog2sql_util.py中的decode(“utf-8”)替换为decode(“utf-8”,“ignore”)
不行的话换成decode(“gbk”,“ignore”)
我是用的gbk才行

猜你喜欢

转载自blog.csdn.net/weixin_43288999/article/details/119104027