- 19.1.3.1 GTID 格式与存储19.1.3.1 GTID Format and Storage
- 19.1.3.2 GTID 生命周期19.1.3.2 GTID Life Cycle
- 19.1.3.3 GTID 自动定位19.1.3.3 GTID Auto-Positioning
- 19.1.3.4 使用 GTID 设置复制19.1.3.4 Setting Up Replication Using GTIDs
- 19.1.3.5 使用 GTID 进行故障切换和扩展19.1.3.5 Using GTIDs for Failover and Scaleout
- 19.1.3.6 从没有 GTID 的源复制到有 GTID 的副本19.1.3.6 Replication From a Source Without GTIDs to a Replica With GTIDs
- 19.1.3.7 使用 GTID 的复制限制19.1.3.7 Restrictions on Replication with GTIDs
- 19.1.3.8 操作 GTID 的存储函数示例19.1.3.8 Stored Function Examples to Manipulate GTIDs
本节解释了使用全局事务标识符(GTID)的基于事务的复制。使用 GTID 时,每个事务在源服务器提交并由任何副本应用时都可以被识别和跟踪;这意味着在使用 GTID 时启动新副本或切换到新的源时,不需要引用日志文件或日志文件中的位置,从而大大简化了这些操作。由于基于 GTID 的复制完全以事务为基础,因此可以很容易地确定源和副本是否一致;只要源上提交的所有事务也在副本上提交,就保证了两者之间的一致性。您可以使用基于语句或基于行的 GTID 复制(参见 第 19.2.1 节,“复制格式”);然而,为了获得最佳效果,我们建议使用基于行的格式。This section explains transaction-based replication using global transaction identifiers (GTIDs). When using GTIDs, each transaction can be identified and tracked as it is committed on the originating server and applied by any replicas; this means that it is not necessary when using GTIDs to refer to log files or positions within those files when starting a new replica or failing over to a new source, which greatly simplifies these tasks. Because GTID-based replication is completely transaction-based, it is simple to determine whether sources and replicas are consistent; as long as all transactions committed on a source are also committed on a replica, consistency between the two is guaranteed. You can use either statement-based or row-based replication with GTIDs (see Section 19.2.1, “Replication Formats”); however, for best results, we recommend that you use the row-based format.
GTID 始终在源和副本之间保持。这意味着您可以通过检查任何副本的二进制日志,始终确定应用于其上的任意事务的来源。此外,一旦具有给定 GTID 的事务在某个服务器上提交,该服务器将忽略任何随后具有相同 GTID 的事务。因此,在源上提交的事务在副本上最多只能应用一次,这有助于保证一致性。GTIDs are always preserved between source and replica. This means that you can always determine the source for any transaction applied on any replica by examining its binary log. In addition, once a transaction with a given GTID is committed on a given server, any subsequent transaction having the same GTID is ignored by that server. Thus, a transaction committed on the source can be applied no more than once on the replica, which helps to guarantee consistency.
本节讨论以下主题:This section discusses the following topics:
GTID 是如何定义和创建的,以及它们在 MySQL 服务器中的表示方式(参见 第 19.1.3.1 节,“GTID 格式和存储”)。How GTIDs are defined and created, and how they are represented in a MySQL server (see Section 19.1.3.1, “GTID Format and Storage”).
GTID 的生命周期(参见 第 19.1.3.2 节,“GTID 生命周期”)。The life cycle of a GTID (see Section 19.1.3.2, “GTID Life Cycle”).
用于同步使用 GTID 的副本和源的自动定位功能(参见 第 19.1.3.3 节,“GTID 自动定位”)。The auto-positioning function for synchronizing a replica and source that use GTIDs (see Section 19.1.3.3, “GTID Auto-Positioning”).
设置和启动基于 GTID 的复制的一般步骤(参见 第 19.1.3.4 节,“使用 GTID 设置复制”)。A general procedure for setting up and starting GTID-based replication (see Section 19.1.3.4, “Setting Up Replication Using GTIDs”).
使用 GTID 时提供新复制服务器的建议方法(参见 第 19.1.3.5 节,“使用 GTID 进行故障转移和扩展”)。Suggested methods for provisioning new replication servers when using GTIDs (see Section 19.1.3.5, “Using GTIDs for Failover and Scaleout”).
使用基于 GTID 的复制时您应注意的限制和局限(参见 第 19.1.3.7 节,“使用 GTID 进行复制的限制”)。Restrictions and limitations that you should be aware of when using GTID-based replication (see Section 19.1.3.7, “Restrictions on Replication with GTIDs”).
可以使用的存储函数来处理 GTID(参见 第 19.1.3.8 节,“操作 GTID 的存储函数示例”)。Stored functions that you can use to work with GTIDs (see Section 19.1.3.8, “Stored Function Examples to Manipulate GTIDs”).
有关 MySQL 服务器选项和与基于 GTID 的复制相关的变量的信息,请参见 第 19.1.6.5 节,“全局事务 ID 系统变量”。另请参见 第 14.18.2 节,“用于全局事务标识符 (GTID) 的函数”,其中描述了 MySQL 8.4 支持的 GTID SQL 函数。For information about MySQL Server options and variables relating to GTID-based replication, see Section 19.1.6.5, “Global Transaction ID System Variables”. See also Section 14.18.2, “Functions Used with Global Transaction Identifiers (GTIDs)”, which describes SQL functions supported by MySQL 8.4 for use with GTIDs.