A replica with the same server_uuid/server_id as this replica has connected to the source;
异常现象:
(1236, "A replica with the same server_uuid/server_id as this replica has connected to the source; the first event 'binlog.***' at 4, the last event read from '.\\binlog.***' at *****, the last byte read from '.\\binlog.***' at *****.")
异常原因:
多个程序不设定 server_id 同时读取同一个MySQL的binlog会出现此异常。
解决方案:
每个读 binlog 的程序,在连接 MySQL 时指定唯一的 server_id(1-4294967295 之间,不与主库 / 其他程序重复),MySQL 会通过 server_id 区分不同客户端,避免冲突。
以下是 Python 示例(使用 pymysqlreplication 库):
from pymysqlreplication import BinLogStreamReader from pymysqlreplication.row_event import DeleteRowsEvent, UpdateRowsEvent, WriteRowsEvent # 程序 1:server_id=100 stream1 = BinLogStreamReader( connection_settings={ "host": "localhost", "port": 3306, "user": "repl", "passwd": "123456" }, server_id=100, # 唯一ID log_file="binlog.000123", log_pos=4, resume_stream=True, only_events=[DeleteRowsEvent, UpdateRowsEvent, WriteRowsEvent] ) # 程序 2:server_id=101(必须不同) stream2 = BinLogStreamReader( connection_settings={ "host": "localhost", "port": 3306, "user": "repl", "passwd": "123456" }, server_id=101, # 唯一ID log_file="binlog.000123", log_pos=4, resume_stream=True, only_events=[DeleteRowsEvent, UpdateRowsEvent, WriteRowsEvent] )

浙公网安备 33010602011771号