mysql tutorialThe column introduces what is the GTID-based replication mode of Mysql
Recommended (free): mysql tutorial
##GTID definition
GTID (Global Transaction Identifier) Global transaction identifier. GTID is a major improvement on master-slave replication introduced in version 5.6. Compared with the previous version of master-slave replication based on Binlog file Position, GTID-based master-slave replication has higher data consistency and more robust master-slave data replication. Switchover and failover are less error-prone and rarely require human intervention.Representation method
GTID = server_uuid:transaction_idThe GTID is usually recorded in the MySQL system variable
@@GLOBAL In .gtid_executed and system table
mysql.gtid_executed, the system variable
@@GLOBAL.gtid_executed is in memory and belongs to non-persistent storage, while the system table mysql.gtid_executed belongs to persistent storage. storage.
The advantages of GTID over traditional replication
and
log_pos
GTID restrictions
cannot be used
cannot be used within a transaction
Master-slave replication flow chart
##GTID life cycle
When a transaction is executed and committed on a main database , then this transaction will be assigned a gtid associated with the main library uuid, and this gtid will be written to the binlog file of the main library.
When a transaction is submitted, the gtid of the transaction will be quickly added to the system variable gtid_executed
In the table.
The binlog on the main library is transferred to the slave library through the master-slave replication protocol, and written to the relay log (relay log) of the slave library, and read from the slave library For the gtid and corresponding transaction information in the relay log, set
If multiple threads concurrently apply the same For a transaction, such as multiple threads setting gtid_next to the same value, MySQL Server only allows one of the threads to execute.
Traditional replacement GTID replication mode
Configure GTIDmysql> SET @@global.read_only = ON;
Restart the master and slave servers in sequence;mysql> CHANGE MASTER TO MASTER_HOST = host, MASTER_PORT = port, MASTER_USER = user, MASTER_PASSWORD = password, MASTER_AUTO_POSITION = 1;5. Enable replication
mysql> START SLAVE;6, Verify master-slave replication
mysql> show slave status \G
The above is the detailed content of Understand Mysql's GTID-based replication mode. For more information, please follow other related articles on the PHP Chinese website!