SoFunction
Updated on 2025-03-02

The difference between Mysql master and slave GTID and binlog

The difference between Mysql master-slave GTID and binlog

Recently, I saw that the database synchronization was synchronized by gtid to build masters and slaves. This is the first time I have encountered it. Let’s learn about the difference between them and the binlog we often use.

MySQL GTID (Global Transaction Identifier) ​​and binlog (binary log) are two different mechanisms used to build master-slave replication.

GTID is a global transaction identifier introduced by MySQL version 5.6 to track and identify transactions during replication. Each transaction is assigned a globally unique GTID, regardless of which database instance the transaction is executed on. GTID ensures that there are no data conflicts or data loss in master-slave replication. When using GTID for master-slave replication configuration, the master library writes the transaction's GTID information to the binlog and transmits the binlog to the slave library. The slave library uses GTID to determine whether a transaction has been copied, thereby maintaining the consistency of the master-slave data.

binlog is a binary log of MySQL that records all changes to the database.

It is a file-based log that can be used to restore a database to a specific point in time or to apply changes to other database instances.

In master-slave replication, the main library writes the change operations to the binlog and transmits the binlog to the slave library. The slave library plays the change operations on the main library according to the content in the binlog, thereby realizing data replication.

Key differences

1. GTID is a transaction-based identifier, while binlog is a log based on change operations. GTID ensures orderly replication of transactions between master and slave, while binlog only records the content of the change operation.

2. GTID can avoid data conflicts or data loss in master-slave replication because each transaction has a unique identifier. And binlog requires correct application of changes on the library to ensure data consistency.

3. GTID is easier to configure and manage compared to binlog because it does not require manual setup and maintenance of binlog file name and location information.

4. GTID can also support multi-master replication, that is, a slave library can be connected to multiple master libraries for replication, while binlog is generally used for replication between a single master library and a single slave library.

Summarize

Overall, GTID is a more advanced replication mechanism that provides simpler and more reliable master-slave replication configuration.

It ensures data consistency between master and slave and is easier to manage and maintain.

binlog is the basis of GTID, which records the details of changes and replays these operations on the library.

The above is personal experience. I hope you can give you a reference and I hope you can support me more.