GTID (Global Transaction Identifier)
In plain English
Plain definition
A unique ID stamped on every committed database transaction so replicas can track exactly which transactions they have applied, without relying on binary log file offsets.
Traditional MySQL replication tracked position using (binlog_file, binlog_position) tuples, which are meaningless outside the specific server that generated them. A replica promoted to master after a failover had no reliable way to tell other replicas where to resume, because the new master’s binlog files start their own independent offset sequence. GTIDs solve this by tagging every transaction with a tuple of the form source_uuid:transaction_id (for example 3E11FA47-71CA-11E1-9E33-C80AA9429562:23) at commit time, written into the binlog itself. Because the identifier travels with the transaction through relay logs and across any number of hops, a replica can compare its own GTID set (the union of all executed transaction identifiers, tracked in gtid_executed) against a candidate source and compute the exact delta of missing transactions, regardless of file rotation or topology changes.
In practice this means CHANGE REPLICATION SOURCE TO SOURCE_AUTO_POSITION=1 (CHANGE MASTER TO MASTER_AUTO_POSITION=1 before MySQL 8.4, which removed that statement): replicas no longer need an operator or orchestration tool to supply exact binlog coordinates after a failover. Group Replication requires GTIDs, and failover tools use this property to automate promotion and repointing without manual coordinate surgery. GTID sets also make it possible to safely skip a transaction that fails on one replica (via gtid_next injection of an empty transaction) without desynchronising the replica’s notion of position, something that was fragile and error-prone under legacy positional replication. Skipping a transaction still leaves that replica’s data different from the source, so confirm the divergence is acceptable first.
- An errant transaction is a GTID present on one server (for example a replica, or a demoted primary that took writes) but absent from the rest of the topology. They usually surface when a replica is repointed or promoted, because the new source’s binlog lacks those transactions. Detect them with the read-only check
GTID_SUBTRACT(replica_gtid_executed, source_gtid_executed). Before changing anything, inspect the errant transactions withmysqlbinlogand decide whether to replay them on the source or discard them. Injecting an empty transaction with the same GTID on the source (and other servers) only hides the divergence, because the replica’s data stays different, so do it only when that divergence is acceptable. Rebuilding the replica destroys its current data, so take a backup first. Do not editgtid_purgedto hide the divergence. - Under statement-based replication, functions like
UUID()can produce divergent results per replica (MySQL treatsNOW()as safe); GTID tracking does not itself solve this, so use row-based replication where such statements occur. gtid_executedis stored as compact intervals perserver_uuid, so it stays small even on servers with long uptime, and purging old binary logs does not require resetting GTID state.RESET MASTER(RESET BINARY LOGS AND GTIDSin MySQL 8.4 and later, where the old statement was removed) deletes all binary logs and clears bothgtid_executedandgtid_purged. On a source with replicas this breaks replication and is hard to reverse. Use it only on a fresh or fully rebuilt topology after taking backups, and reset or re-clone every replica to match.- Cloned servers cause a separate problem. Because the UUID component is tied to
server_uuid, cloning a server’s data directory without regeneratingauto.cnfleaves two servers with the same UUID, which usually causes replication errors (such as an I/O thread failure). To fix it, stopmysqld, back up and removeauto.cnffrom the data directory, then start the server so it generates a new UUID.
GTIDs are required by MySQL Group Replication, and so by InnoDB Cluster, because they turn replication position into an algebraic set operation instead of a filesystem coordinate lookup. In operation, the failure that matters most is errant transactions piling up after split-brain writes to a demoted primary. Catching them means comparing GTID sets across all nodes before re-attaching a former primary as a replica, since blind reattachment can leave the former primary holding transactions the rest of the topology lacks, which can cause data divergence or failures if it is later promoted.
Legacy Reference
https://dev.mysql.com/doc/refman/8.0/en/replication-gtids.htmlAbout this page
Credited to
Dates
Published
Was this useful?
Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.
Found this useful? Follow KBY for more like it.
Recommended reading
More from KBY that goes with this term.