How to read a mysql binlog
Asked Answered
Q

5

5

I want to write a service to tail the mysql bin log to get notifications about database changes.

Is there an open source library that reads and parses mysql bin log in ROW format?

Quaff answered 3/6, 2015 at 0:50 Comment(1)
There are open source and proprietary solutions that can do this, but "which library can I use to ...?" questions are considered off-topic for Stack Overflow.Celiotomy
O
6

Use mysqlbinlog.

The server's binary log consists of files containing “events” that describe modifications to database contents. The server writes these files in binary format. To display their contents in text format, use the mysqlbinlog utility. You can also use mysqlbinlog to display the contents of relay log files written by a slave server in a replication setup because relay logs have the same format as binary logs.

Source: https://dev.mysql.com/doc/refman/5.6/en/mysqlbinlog.html

Oat answered 3/6, 2015 at 1:37 Comment(0)
W
1

I use this one: https://github.com/alibaba/canal.

It's written in Java and with a couple of changes in the conf file, you are ready to go, the inner detail is taken care for you.

The documentation is in Chinese. But the code structure is straight-forward and the conf file's variable names are self-explaining, so with some effort, you might be able to figure it out:)

Wheels answered 27/8, 2019 at 7:12 Comment(0)
A
0

You can use https://github.com/monothorn/mysql-parser It's based on sqlparse in python. Since you have binlog row format enabled, you can checkout https://github.com/noplay/python-mysql-replication

Azygous answered 19/10, 2018 at 15:45 Comment(0)
B
0

You can use the below command to read the bin-log file:

read -p "Enter the Log File Name : " logfilename; mysqlbinlog $logfilename | grep -i ^use | sort | uniq -c | sort -rn
Brenneman answered 2/4, 2019 at 6:15 Comment(0)
N
0

Two project writen in java from github:mysql-binlog-connector-java and mysql-binlog-connector-java can help your parse mysql binlog.

Noellenoellyn answered 13/1, 2021 at 1:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.