如果把生产环境的binlog,放到本地测试环境用binlog2sql解析,直接读取会发生如下错误:
[root@testdb1 mysql]# python /root/binlog2sql-master/binlog2sql/binlog2sql.py -h 192.168.119.130 -uroot -pchengce243 --start-file mysql-bin.000144 > /tmp/binlog2sql-000144.log
Traceback (most recent call last):
File "/root/binlog2sql-master/binlog2sql/binlog2sql.py", line 149, in <module>
back_interval=args.back_interval, only_dml=args.only_dml, sql_type=args.sql_type)
File "/root/binlog2sql-master/binlog2sql/binlog2sql.py", line 53, in __init__
raise ValueError('parameter error: start_file %s not in mysql server' % self.start_file)
ValueError: parameter error: start_file mysql-bin.000144 not in mysql server
解决办法是 把 生产环境的 mysql-bin.000144 替换本地测试环境的 testdb1-bin.000001
只是改了一个名字,但是其实还是解析的是生产环境的 mysql-bin.000144
如果binlog是GTID模式,但是本地测试环境不是GTID模式,就会报如下错误:
[root@testdb1 mysql]# python /root/binlog2sql-master/binlog2sql/binlog2sql.py -h 192.168.119.130 -uroot -pchengce243 --start-file testdb1-bin.000001 > /tmp/binlog2sql-000144.log
Traceback (most recent call last):
File "/root/binlog2sql-master/binlog2sql/binlog2sql.py", line 150, in <module>
binlog2sql.process_binlog()
File "/root/binlog2sql-master/binlog2sql/binlog2sql.py", line 74, in process_binlog
for binlog_event in stream:
File "build/bdist.linux-x86_64/egg/pymysqlreplication/binlogstream.py", line 430, in fetchone
File "build/bdist.linux-x86_64/egg/pymysql/connections.py", line 684, in _read_packet
File "build/bdist.linux-x86_64/egg/pymysql/protocol.py", line 220, in check_error
File "build/bdist.linux-x86_64/egg/pymysql/err.py", line 109, in raise_mysql_exception
pymysql.err.InternalError: (1236, u"Cannot replicate GTID-transaction when @@GLOBAL.GTID_MODE = OFF, at file ./testdb1-bin.000001, position 234.; the first event 'testdb1-bin.000001' at 4, the last event read from './testdb1-bin.000001' at 299, the last byte read from './testdb1-bin.000001' at 299.")
[root@testdb1 mysql]# python /root/binlog2sql-master/binlog2sql/binlog2sql.py -h 192.168.119.130 -uroot -pchengce243 --start-file testdb1-bin.000001 > /tmp/binlog2sql-000144.log
解决办法:
set @@GLOBAL.GTID_MODE = OFF_PERMISSIVE;
解析完之后,记得把GTID_MOD 关掉
set @@GLOBAL.GTID_MODE = OFF;