TheRobotLearns Platform · ProxySQL: from first install to production
GTID-Based Causal Reads with the MySQL Binlog Reader
Learning objectives
- Confirm backend GTID tracking and causal-read support before configuring routing.
- Place MySQL Binlog Reader near the database, then configure its connection, ports, and log-file settings.
- Enable GTID tracking in MySQL by setting `gtid_mode`, `enforce_gtid_consistency`, and `session_track_gtids=OWN_GTID`.
- Point `mysql_servers` rows to the Binlog Reader using `gtid_port`, then load and save them.
- Explain how ProxySQL selects a destination-hostgroup server that has applied the read's required transaction.
- Recognize reads may wait or time out without an eligible destination server at the required GTID, then plan writer-fallback routing and topology policy.
Why causal reads need tracking
Since ProxySQL 2.0, ProxySQL can track executed GTID in real time from all MySQL servers in a replication topology. Adaptive query routing based on GTID tracking allows ProxySQL to provide causal reads.
The MySQL Binlog Reader reports the transactions executed on each configured database server. ProxySQL uses those positions to route reads to a replica where the required transaction has already executed. The required transaction is the write that the read depends on. If no server in the destination hostgroup has reached the required position, the read can wait and time out. Writer fallback requires an appropriate routing and topology policy; it is not automatically added to a reader-only destination.
This solution scales very well with limited network usage and is being already tested in production environments. For MySQL backends, it requires ProxySQL 2.0+, MySQL 5.7.5 or newer, replication binlog format ROW, and GTID enabled. The MySQL Binlog Reader should be running as close as possible to the MySQL database it is reading from.
Place the reader near MySQL
You install the MySQL Binlog Reader, then need to decide where it runs. For best results, it should run as close as possible to the MySQL database it reads from. That keeps network usage limited while it reports executed transactions.
Multiple setup routes exist: install a package, use the official Docker image, use the Amazon AMI, or compile from source. Packages are provided for CentOS, Debian, and Ubuntu. The official Docker image is proxysql/proxysql-mysqlbinlog, and the pull command is docker pull proxysql/proxysql-mysqlbinlog:latest. You can clone the GitHub repository and run make; Amazon AMI is marked as coming soon.
You configure the reader with option arguments at startup. The arguments choose the MySQL host, user, password, MySQL port, listen port, and log file. The example starts the reader against MySQL on 127.0.0.1, listens on 3307, and writes a log file.
proxysql_binlog_reader -h 127.0.0.1 -u root -proot -P 3306 -l 3307 -L /var/log/proxysql_binlog_reader.logThe reader then reports transactions executed on each configured database server.
Enable backend GTIDs and routing
You have the reader ready. The MySQL backend still has to expose GTIDs the reader can track. ProxySQL causal reads require backend MySQL 5.7.5 or newer, and the backends must be Oracle or Percona MySQL Server. MariaDB uses a different tracking mechanism, so follow the MariaDB causal-read guide instead of these MySQL settings. The MariaDB guide covers MariaDB server settings, reader setup, and routing.
The replication binlog format must be ROW, and GTID must be enabled. Add the MySQL options gtid_mode=ON, enforce_gtid_consistency, and session_track_gtids=OWN_GTID to the configuration. The ProxySQL setup then uses gtid_port with the reader's listen port value shown in the example. On the admin interface, run UPDATE mysql_servers SET gtid_port = 3307. In the shown example, the reader's -l option and the gtid_port value are both 3307.
After editing, run LOAD MYSQL SERVERS TO RUNTIME; SAVE MYSQL SERVERS TO DISK;. The reader reports executed transactions, and ProxySQL uses those positions to select a server that has applied the write a read depends on. The update, load, and save commands are shown in the ProxySQL configuration step.
When reads cannot find GTIDs
You configured the reader, GTID settings, and gtid_port, yet a read may still pause. ProxySQL selects a destination-hostgroup server that has applied the write the read depends on. If no server in the destination hostgroup has reached the required position, the read can wait and time out. Writer fallback requires an appropriate routing and topology policy, and it is not automatically added to a reader-only destination.
The requirements list ProxySQL 2.0 or newer, because older versions do not support causal reads with GTID. They also list Oracle or Percona MySQL 5.7.5 or newer, because older MySQL versions do not have the needed capability. Replication binlog format must be ROW, and GTID must be enabled.
MariaDB follows a different path: use ProxySQL 3.0.12 or newer with binlog reader 2.5.0 and the MariaDB guide. For MySQL, keep the reader close to the database so it can report executed transactions with limited network usage.
Route causal reads through the Binlog Reader
-- Admin interface: use the Binlog Reader listen port from -l 3307.
UPDATE mysql_servers SET gtid_port = 3307;
LOAD MYSQL SERVERS TO RUNTIME;
SAVE MYSQL SERVERS TO DISK;This updates mysql_servers to use the reader listen port shown in the example. The UPDATE mysql_servers SET gtid_port = 3307 statement assigns gtid_port the value 3307. It matches the reader example that starts with -l 3307. The LOAD MYSQL SERVERS TO RUNTIME command is the next command shown after the update. The SAVE MYSQL SERVERS TO DISK command is the final command shown in the ProxySQL config.
Try it: config_layer_sim
Run the admin commands shown for a reader listening on 3307: UPDATE mysql_servers SET gtid_port = 3307; LOAD MYSQL SERVERS TO RUNTIME; SAVE MYSQL SERVERS TO DISK;. Confirm that the UPDATE uses the same value as the reader's -l 3307 option. If a read cannot find a destination server at the required position, the read can wait and time out.
Sources
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
- MySQL Binlog Reader
Do more with an account
- Graded quizzes is available on your account.
- Saving your progress is available on your account.
- Hands-on labs is available on your account.
- AI tutoring is available on your account.