zoukankan      html  css  js  c++  java
  • binlog2sql 解析日志失败 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 0: invalid start byte

    python35 ./binlog2sql.py -h... -P... -u... -p... -B --start-file="mysql-bin.091940" --start-position=43669051 --stop-position=65769997 > /export/logs/redo.sql

    执行报错

    Traceback (most recent call last):
      File "/export/servers/pbmonitor/exps/static/file/mysql_tools/binlog2sql/binlog2sql.py", line 150, in <module>
        binlog2sql.process_binlog()
      File "/export/servers/pbmonitor/exps/static/file/mysql_tools/binlog2sql/binlog2sql.py", line 121, in process_binlog
        self.print_rollback_sql(filename=tmp_file)
      File "/export/servers/pbmonitor/exps/static/file/mysql_tools/binlog2sql/binlog2sql.py", line 129, in print_rollback_sql
        for line in reversed_lines(f_tmp):
      File "/export/servers/pbmonitor/exps/static/file/mysql_tools/binlog2sql/binlog2sql_util.py", line 249, in reversed_lines
        block = block.decode("utf-8")
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 0: invalid start byte

    第249行,修改block.decode为ignore模式

    247     for block in reversed_blocks(fin):
    248         if PY3PLUS:
    249             block = block.decode("utf-8","ignore")
    250         for c in reversed(block):
    251             if c == '
    ' and part:
    252                 yield part[::-1]
    253                 part = ''
    254             part += c
    255     if part:
    256         yield part[::-1]

    参考

    UnicodeDecodeError: 'utf-8' codec can't decode byte..问题

  • 相关阅读:
    __name__在调用时的区别
    Python内置模块--os模块的使用
    查询mysql 表的元数据信息
    nfs服务搭建
    jvm参数设置
    spring boot 集成 beetl
    spring boot 集成 swagger2 四部曲
    JavaScript中的this关键字
    jQuery 基础事件
    jQuery 表单选择器
  • 原文地址:https://www.cnblogs.com/perfei/p/14435375.html
Copyright © 2011-2022 走看看