Skip to content

Instantly share code, notes, and snippets.

@shufo
Created December 18, 2018 10:39
Show Gist options
  • Save shufo/fecedd136ffe97b76dde8d56d3b1c959 to your computer and use it in GitHub Desktop.
Save shufo/fecedd136ffe97b76dde8d56d3b1c959 to your computer and use it in GitHub Desktop.
import json
import boto3
from pymysqlreplication import BinLogStreamReader
from pymysqlreplication.row_event import (
DeleteRowsEvent,
UpdateRowsEvent,
WriteRowsEvent,
)
def main():
stream = BinLogStreamReader(
connection_settings= {
"host": "127.0.0.1",
"port": 3306,
"user": "root",
"passwd": "root"},
server_id=100,
blocking=True,
resume_stream=True,
only_events=[DeleteRowsEvent, WriteRowsEvent, UpdateRowsEvent])
for binlogevent in stream:
for row in binlogevent.rows:
event = {"schema": binlogevent.schema,
"table": binlogevent.table,
"type": type(binlogevent).__name__,
"row": row
}
print(json.dumps(event, sort_keys=True, default=str))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment