Databases 9 min read

Using ProxySQL Binlog Reader to Monitor MySQL GTID Replication

This article introduces the ProxySQL Binlog Reader component, explains its background in read/write splitting and GTID‑based consistency, demonstrates how to configure MySQL servers, create a dedicated user, start the reader on master and replica, and verify its operation through logs and session information.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Using ProxySQL Binlog Reader to Monitor MySQL GTID Replication

The author, a senior database expert with years of experience in MySQL, PostgreSQL, and MongoDB, presents the ProxySQL Binlog Reader component—a lightweight MySQL client that continuously fetches GTID numbers from each MySQL instance to help ProxySQL determine whether master and replica data are consistent.

ProxySQL Binlog Reader was created to address the challenge of stale reads in read/write‑splitting architectures, where three common strategies exist: sending all requests to the master, sending transaction‑level writes to the master, or sending all reads to replicas. Since replicas can lag, GTID comparison provides a reliable way to assess replication delay.

Component Background

By simulating a MySQL replica, the reader pulls only the latest GTID from each instance, which is resource‑efficient. ProxySQL then reads these GTIDs to decide if data can be safely served from a replica.

Demo Environment

Three instances (MySQL 5.7.34, port 5734) are used:

ProxySQL host: 192.168.2.111

Master: 192.168.2.120

Slave: 192.168.2.121

ProxySQL’s admin port is 6032, traffic port 6033, and the gtid_port in mysql_servers is set to 57341.

<mysql:admin:5.5.30>select hostgroup_id, hostname,port,status,gtid_port from mysql_servers;
+--------------+---------------+------+--------+-----------+
| hostgroup_id | hostname      | port | status | gtid_port |
+--------------+---------------+------+--------+-----------+
| 1            | 192.168.2.120 | 5734 | ONLINE | 57341     |
| 2            | 192.168.2.121 | 5734 | ONLINE | 57341     |
+--------------+---------------+------+--------+-----------+
2 rows in set (0.00 sec)

A dedicated user for the reader is created and granted replication privileges:

<mysql: ytt:5.7.34-log> create user binlog_reader identified by 'read';
Query OK, 0 rows affected (0.01 sec)
<mysql: ytt:5.7.34-log> grant replication client, replication slave on *.* to binlog_reader;
Query OK, 0 rows affected (0.00 sec)

The reader is started on each MySQL instance, matching the gtid_port value:

# Master:
root@ytt-large:/tmp# proxysql_binlog_reader -ubinlog_reader -pread -P5734 -h 192.168.2.120 -l57341 -L /tmp/proxysql_mysqlbinlog_reader.log
# Slave:
root@ytt-normal:/tmp# proxysql_binlog_reader -ubinlog_reader -pread -P5734 -h 192.168.2.121 -l57341 -L /tmp/proxysql_mysqlbinlog_reader.log

Log output confirms successful startup and continuous GTID reading:

root@ytt-large:/tmp# tail -f proxysql_mysqlbinlog_reader.log
Starting ProxySQL MySQL Binlog
Sucessfully started
Angel process started ProxySQL MySQL Binlog process 28841
2022-07-18 15:11:04 [INFO] proxysql_binlog_reader version 2.0-3-gd8e0140
2022-07-18 15:11:04 [INFO] Initializing client...
2022-07-18 15:11:04 [INFO] Last executed GTID: '00005734-0000-0000-0000-000000005734:1-2'
2022-07-18 15:11:04 [INFO] Reading binlogs...
root@ytt-normal:/tmp# tail -f proxysql_mysqlbinlog_reader.log
Starting ProxySQL MySQL Binlog
Sucessfully started
Angel process started ProxySQL MySQL Binlog process 22710
2022-07-18 15:11:59 [INFO] proxysql_binlog_reader version 2.0-3-gd8e0140
2022-07-18 15:11:59 [INFO] Initializing client...
2022-07-18 15:11:59 [INFO] Last executed GTID: '00005734-0000-0000-0000-000000005734:1-2'
2022-07-18 15:11:59 [INFO] Reading binlogs...

MySQL session lists show two additional DUMP threads (one per instance) created for the reader:

# Master:
Id: 125
User: binlog_reader
Host: 192.168.2.120:54668
Command: Binlog Dump GTID
State: Master has sent all binlog to slave; waiting for more updates
# Slave:
Id: 1426
User: binlog_reader
Host: 192.168.2.121:54992
Command: Binlog Dump GTID
State: Master has sent all binlog to slave; waiting for more updates

If replication issues occur, corresponding messages appear in the reader’s logs.

The article concludes by noting that this introduction covers the component’s background and usage, with more details to follow in a future post.

Additional information about the SQLE tool, a SQL audit platform from the same community, is provided with links to its repository, documentation, and release page.

MySQLReplicationGTIDDatabase MonitoringProxySQLBinlog Reader
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.