GTID的概念:
A global transaction identifier (GTID) is a unique identifier created and associated with each transaction committed on the server of origin (the source). This identifier is unique not only to the server on which it originated, but is unique across all servers in a given replication topology.
全局事务标识号,分配给每一个在server上提交的事务并且是唯一的。在整个复制拓扑中都是唯一存在的。
GTID的组成
GTID = source_id:transaction_id1
source_id标识原有的server,一般就是source_uuid,
transaction_id是事务提交时决定执行顺序的一个序列号。
gtid_executed表
GTIDs are stored in a table named gtid_executed
, in the mysql
database。
GTID存储在mysql.gtid_executed表中,这个表是在mysql安装或者升级后产生的。
CREATE TABLE gtid_executed (
source_uuid CHAR(36) NOT NULL,
interval_start BIGINT(20) NOT NULL,
interval_end BIGINT(20) NOT NULL,
PRIMARY KEY (source_uuid, interval_start)
)
Warning
As with other MySQL system tables, do not attempt to create or modify this table yourself.
不要去修改它!
其实除了这个表,还有binlog日志中的GTID_LOG_EVENT记录了GTID的值。
GTIDs are stored in the
mysql.gtid_executed
table only whengtid_mode
isON
orON_PERMISSIVE
. The point at which GTIDs are stored depends on whether binary logging is enabled or disabled:
只有当gtid_mode
=on 或者 ON_PERMISSIVE时,GTID才会被写入到gtid_executed
表中。
- 如果binlog没开启。事务的GTID会被写入到
gtid_executed
表中
If binary logging is disabled (
log_bin
isOFF
), or iflog_slave_updates
is disabled, the server stores the GTID belonging to each transaction together with the transaction in the table.
- 如果binlog启用。当binlog发生切换或者server 关闭时,原本写入binlog日志中的事务的GTID将被写入到
gtid_executed
表中
If binary logging is enabled (
log_bin
isON
), whenever the binary log is rotated or the server is shut down, the server writes GTIDs for all transactions that were written into the previous binary log into themysql.gtid_executed
table. This situation applies on a replication source server, or a replica where binary logging is enabled.