MySQLDev & Eng

Content type: Hands-on

5 min read

How to update MySQL replication filters without rebuilding the replica

Percona has published a walkthrough for excluding and re-including tables on a live MySQL replica using mydumper and binlog coordinates, without touching the primary or rebuilding anything.

Article · Dev & Eng
Reading
5 min
Code
5

Percona has published a walkthrough for excluding and re-including tables on a live MySQL replica using mydumper and binlog coordinates, without touching the primary or rebuilding anything.

Every MySQL primary-replica architecture reaches a point where not every replica needs every piece of data. An analytics team doesn't need the sessions table; a billing team doesn't need the product catalog. That is what replication filters exist for: REPLICATE_DO_TABLE, REPLICATE_IGNORE_TABLE and their variants.

The problem shows up when the requirement changes after the replica is already in production, serving read traffic. Bhuvanes Waran, from Percona, published a step-by-step guide for this on November 27, 2026, on the Percona Database Blog, with one detail that matters to anyone running databases at scale: no step touches the primary server.

Taking a table out of replication is the easy part

Stopping the replication of an existing table is trivial. It means stopping the replica, changing the filter and turning it back on:

sql
STOP REPLICA;
CHANGE REPLICATION FILTER REPLICATE_IGNORE_TABLE = (sbtest.sbtest3);
START REPLICA;

After START REPLICA, SHOW REPLICA STATUS\G starts showing sbtest.sbtest3 in the Replicate_Ignore_Table field, and the SQL thread simply skips any binlog event related to that table. There is no rebuild, no perceptible downtime, and the replica keeps applying everything else normally.

To confirm that the filter really took effect, the post suggests a simple trick: set the MySQL client's pager to md5sum and run the same SELECT * FROM sbtest.sbtest3 three times in a row. If the hash doesn't change across the three runs, the table has stopped receiving writes from the primary. It is a cheap check, with nothing to instrument, and worth keeping as a checklist habit before calling any change done.

Why simply restoring a dump doesn't solve it

The reverse path, bringing a table back into replication, is where most mistakes happen. The temptation is to take a dump from the primary (or from another replica), restore it on the target replica and run START REPLICA. That fails for live tables: between the moment of the dump and the moment replication resumes applying events, any write in between creates inconsistency, and the most common symptom is a replication error that forces a rebuild of the entire replica.

Percona's walkthrough solves this by tying the dump to an exact position in the primary's binlog, and making the replica advance to that exact position before restoring. There are four steps that need to happen in the right order.

1. Stop the replica at the right point

If the replica uses multi-threaded replication (MTS), an abrupt STOP REPLICA can leave the applier with gaps between parallel transactions. The right command in that case is:

sql
START REPLICA UNTIL SQL_AFTER_MTS_GAPS;

This lets the parallel threads close any pending gaps before the SQL thread stops on its own, consistently. With a single-threaded applier, a straight STOP REPLICA is enough. It is the kind of detail that separates a documented procedure from a procedure that actually works under real load.

2. Consistent dump with mydumper, without touching the primary

The dump doesn't have to come from the primary: it can come from any healthy replica, as long as mydumper's --replica-data flag is enabled. It captures the primary's binlog position corresponding to the snapshot, even when the dump is taken from an intermediate replica.

bash
mydumper --host=172.31.94.154 -u root -p PASSWORD \
 --tables-list=sbtest.sbtest3 --trx-tables --threads=4 \
 --outputdir=/tmp/mydump_export --replica-data

The metadata file generated alongside the dump holds the decisive information, in the [replication] section:

SOURCE_LOG_FILE = "binlog.000024"
SOURCE_LOG_POS = 950744300

That pair, file and position, is the link between the dump you have in hand and the exact point in the replication stream it corresponds to. Losing that reference is the same as taking a dump without knowing which instant it is a snapshot of.

3. Bring the replica up to the dump's position, not beyond

With the file and the position in hand, the target replica is instructed to apply events only up to that point:

sql
START REPLICA UNTIL SOURCE_LOG_FILE='binlog.000024', SOURCE_LOG_POS=950744300;

The replica keeps applying the backlog normally, but stops on its own exactly at the position that corresponds to the mydumper snapshot. In the post's example, Seconds_Behind_Source went as high as almost 3,000 seconds of lag while the replica advanced toward the target.

4. Restore the dump and re-enable the filter

With the replica stopped at exactly that point, the dump is restored (mydumper has myloader as its counterpart, built to consume the same output format). Only after that is the filter updated to include the table again, and normal replication is turned back on with START REPLICA, without the UNTIL clause. From there, the binlog stream resumes from where the dump left off, with no gap and without the table being out of date relative to the rest of the schema.

What this changes for those who don't live on DBA on-call duty

This walkthrough matters beyond the pure database team. Squads that maintain their own read replica for a service, an analytics pipeline or a reporting cache often inherit filter decisions made months ago, and need to adjust them when the product's data scope changes.

Knowing that it is possible to add a table back without recreating the replica from scratch changes the risk calculation of a scope change: instead of scheduling a maintenance window and a full rebuild, which on large databases can take hours, the procedure becomes an auditable sequence of commands, with clear verification points at each step.

What remains open

The walkthrough shown uses classic binlog coordinates (SOURCE_LOG_FILE/SOURCE_LOG_POS) to sync the replica's position with the dump. In topologies with GTID enabled, those coordinates give way to SOURCE_AUTO_POSITION, and in Percona XtraDB (Galera) clusters the concept of per-node position is different. For anyone operating those topologies, the specific position-sync commands will need adaptation before going to production.

Translated from the Brazilian Portuguese original · Read the original