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