菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
492
0

binlog2sql 解析日志失败 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 0: invalid start byte

原创
05/13 14:22
阅读数 1197

 

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 == '\n' 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..问题

 

发表评论

0/200
492 点赞
0 评论
收藏