Databases 6 min read

FLUSH Statements Write to Binlog on read_only MySQL Replicas Causing GTID Inconsistency

The article explains how executing FLUSH commands on MySQL replicas that are in read_only mode can still write to the binary log, generate new GTIDs, and lead to GTID mismatches between primary and replica, especially when tools like ClickHouse issue such statements.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
FLUSH Statements Write to Binlog on read_only MySQL Replicas Causing GTID Inconsistency

Background: In a high‑availability management platform, a MySQL replica entered read_only and super_read_only mode and was expelled from the HA cluster because its GTID differed from the primary.

Problem discovery: Checking SHOW MASTER STATUS and SHOW SLAVE STATUS revealed an extra GTID on the replica. Searching the binlog showed that a FLUSH TABLES statement had been written, generating a new GTID.

Local test: Executing FLUSH TABLES on a replica with read_only enabled also writes to the binlog and creates a new GTID. Additional tests demonstrated that many FLUSH‑type statements (e.g., FLUSH ENGINE LOGS , FLUSH ERROR LOGS , FLUSH PRIVILEGES , FLUSH OPTIMIZER_COSTS , FLUSH QUERY CACHE , FLUSH SLOW LOGS , FLUSH STATUS , FLUSH USER_RESOURCES ) are logged even when the server is read‑only.

Some forms of the FLUSH statement are not logged because they could cause problems if replicated to a replica: FLUSH LOGS and FLUSH TABLES WITH READ LOCK. For a syntax example, see Section 13.7.6.3, “FLUSH Statement”. The FLUSH TABLES, ANALYZE TABLE, OPTIMIZE TABLE, and REPAIR TABLE statements are written to the binary log and thus replicated to replicas. This is not normally a problem because these statements do not modify table data. However, this behavior can cause difficulties under certain circumstances. If you replicate the privilege tables in the mysql database and update those tables directly without using GRANT, you must issue a FLUSH PRIVILEGES on the replicas to put the new privileges into effect. In addition, if you use FLUSH TABLES when renaming a MyISAM table that is part of a MERGE table, you must issue FLUSH TABLES manually on the replicas. These statements are written to the binary log unless you specify NO_WRITE_TO_BINLOG or its alias LOCAL.

Observation: ClickHouse may issue FLUSH TABLES during data synchronization, which can also cause the replica to generate GTID changes.

Summary

The article warns that certain FLUSH management commands are written to the binlog even on read_only replicas, leading to GTID mismatches; users of ClickHouse should be aware of possible FLUSH TABLES execution during synchronization.

MySQLbinlogReplicationGTIDread_onlyflush
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.