如果把生產環境的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;