在测试BinLogStreamReader的使用过程中,发现脚本在被终止后,mysql上的binlog dump线程一直存在引发出2个问题,1是如何优雅的关闭python脚本,直接使用ctrl+c的方式,控制台出现一堆异常。比较好的方式如下:
stream = BinLogStreamReader(connection_settings=MYSQL_SETTINGS,
server_id=503333,
blocking=True)
try:
for binlogevent in stream:
print("event_type",binlogevent.event_type)
if binlogevent.event_type == 30:
for row in binlogevent.rows:
print(row)