binlog mysql stream reader

pip install mysql-replication
from pymysqlreplication import BinLogStreamReader

from pymysqlreplication.row_event import (
    DeleteRowsEvent,
    UpdateRowsEvent,
    WriteRowsEvent,
)

__cfg = {}
__cfg['host'] = "localhost"
__cfg['user'] = "root"
__cfg['password'] = "root"
server_id = 1
log_file = "/var/log/mysql/mysql-bin"
log_pos = 1
schemas = ["id", "name"]
tables = "test"

stream = BinLogStreamReader(connection_settings= __cfg,server_id=server_id, only_events=[DeleteRowsEvent, WriteRowsEvent, UpdateRowsEvent],           log_file=log_file,log_pos=log_pos,resume_stream=True, blocking=True,only_tables=tables,slave_heartbeat=10)

for binlogevent in stream:
    for row in binlogevent.rows:
        print row


Leave a Reply

Your email address will not be published. Required fields are marked *