8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 19 复制 / 19.4 复制解决方案 / 19.4.9 使用异步连接故障切换切换源和副本
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

19.4.9 使用异步连接故障转移切换源和副本19.4.9 Switching Sources and Replicas with Asynchronous Connection Failover

您可以使用异步连接故障转移机制,在副本到其源的现有连接失败后,自动建立到新源的异步(源到副本)复制连接。异步连接故障转移机制可用于保持副本与多个 MySQL 服务器或共享数据的服务器组的同步。潜在源服务器的列表存储在副本上,并且在连接失败时,将根据您设置的加权优先级从列表中选择新源。You can use the asynchronous connection failover mechanism to establish an asynchronous (source-to-replica) replication connection to a new source automatically, after the existing connection from a replica to its source fails. The asynchronous connection failover mechanism can be used to keep a replica synchronized with multiple MySQL servers or groups of servers that share data. The list of potential source servers is stored on the replica, and in the event of a connection failure, a new source is selected from the list based on a weighted priority that you set.

异步连接故障转移机制还支持组复制拓扑,通过自动监控组成员变化并区分主服务器和从服务器。当你将一个组成员添加到源列表并将其定义为托管组的一部分时,异步连接故障转移机制会更新源列表,以使其与成员变化保持一致,在成员加入或离开时自动添加和移除组成员。只有处于多数的在线组成员会被用于连接和获取状态。即使托管组的最后一个成员离开了组,它也不会被自动移除,以保持托管组的配置。然而,如果不再需要,你可以手动删除托管组。The asynchronous connection failover mechanism also supports Group Replication topologies, by automatically monitoring changes to group membership and distinguishing between primary and secondary servers. When you add a group member to the source list and define it as part of a managed group, the asynchronous connection failover mechanism updates the source list to keep it in line with membership changes, adding and removing group members automatically as they join or leave. Only online group members that are in the majority are used for connections and obtaining status. The last remaining member of a managed group is not removed automatically even if it leaves the group, so that the configuration of the managed group is kept. However, you can delete a managed group manually if it is no longer needed.

异步连接故障转移机制还使得作为管理复制组一部分的副本能够在当前接收端(组的主服务器)发生故障时自动重新连接到发送端。此功能适用于组复制,在单主模式下配置的组中,其中组的主服务器是一个副本,该副本使用该机制的复制通道。此功能的设计目的是让发送端组和接收端组即使在一些成员暂时不可用的情况下也能保持同步。它还可将接收端组与一个或多个不属于管理组的发送端同步。未加入复制组的副本无法使用此功能。The asynchronous connection failover mechanism also enables a replica that is part of a managed replication group to automatically reconnect to the sender if the current receiver (the primary of the group) fails. This feature works with Group Replication, on a group configured in single-primary mode, where the group’s primary is a replica that has a replication channel using the mechanism. The feature is designed for a group of senders and a group of receivers to keep synchronized with each other even when some members are temporarily unavailable. It also synchronizes a group of receivers with one or more senders that are not part of a managed group. A replica that is not part of a replication group cannot use this feature.

使用异步连接故障转移机制的要求如下:The requirements for using the asynchronous connection failover mechanism are as follows:

  • 源和副本上必须使用 GTID (gtid_mode=ON),并且副本上必须启用 CHANGE REPLICATION SOURCE TO 语句的 SOURCE_AUTO_POSITION 选项,以便对源的连接使用 GTID 自动定位。GTIDs must be in use on the source and the replica (gtid_mode=ON), and the SOURCE_AUTO_POSITION option of the CHANGE REPLICATION SOURCE TO statement must be enabled on the replica, so that GTID auto-positioning is used for the connection to the source.

  • 该频道的源列表中所有源服务器上必须存在相同的复制用户账户和密码。此账户用于连接每个源。您可以为不同的频道设置不同的账户。The same replication user account and password must exist on all the source servers in the source list for the channel. This account is used for the connection to each of the sources. You can set up different accounts for different channels.

  • 复制用户账户必须在性能模式表上被授予 SELECT 权限,例如,通过执行 GRANT SELECT ON performance_schema.* TO 'repl_user';The replication user account must be given SELECT permissions on the Performance Schema tables, for example, by issuing GRANT SELECT ON performance_schema.* TO 'repl_user';

  • 复制用户账户和密码不能在用于启动复制的语句中指定,因为它们需要在自动重新启动连接到备用源时可用。必须在副本上使用 CHANGE REPLICATION SOURCE TO 语句为通道设置,并记录在复制元数据存储中。The replication user account and password cannot be specified on the statement used to start replication, because they need to be available on the automatic restart for the connection to the alternative source. They must be set for the channel using the CHANGE REPLICATION SOURCE TO statement on the replica, and recorded in the replication metadata repositories.

  • 如果用于异步连接故障切换机制的通道位于 Group Replication 单主模式组的主服务器上,副本之间的异步连接故障切换默认也是启用的。在这种情况下,复制通道以及通道的复制用户账户和密码必须在复制组的所有从服务器上设置,并在任何新加入的成员上设置。如果使用 MySQL 的克隆功能配置新服务器,这一切会自动完成。If the channel where the asynchronous connection failover mechanism is in use is on the primary of a Group Replication single-primary mode group, asynchronous connection failover between replicas is also active by default. In this situation, the replication channel and the replication user account and password for the channel must be set up on all the secondary servers in the replication group, and on any new joining members. If the new servers are provisioned using MySQL’s clone functionality, this all happens automatically.

    Important

    如果您不希望在这种情况下在副本之间发生异步连接故障转移,可以通过为该组禁用成员操作mysql_start_failover_channels_if_primary来禁用它,使用group_replication_disable_member_action函数。当该功能被禁用时,您无需在辅助组成员上配置复制通道,但如果主节点离线或进入错误状态,该通道的复制将停止。If you do not want asynchronous connection failover to take place between replicas in this situation, disable it by disabling the member action mysql_start_failover_channels_if_primary for the group, using the group_replication_disable_member_action function. When the feature is disabled, you do not need to configure the replication channel on the secondary group members, but if the primary goes offline or into an error state, replication stops for the channel.

MySQL InnoDB ClusterSet 可用于通过将主 InnoDB 集群与其自身在其他位置(例如不同数据中心)的一个或多个副本链接起来,为 InnoDB 集群部署提供灾难容错。考虑使用此解决方案来简化新多组部署的设置,以实现复制、故障转移和灾难恢复。您可以将现有的组复制部署作为 InnoDB 集群来采用。MySQL InnoDB ClusterSet is available to provide disaster tolerance for InnoDB Cluster deployments by linking a primary InnoDB Cluster with one or more replicas of itself in alternate locations, such as different datacenters. Consider using this solution instead to simplify the setup of a new multi-group deployment for replication, failover, and disaster recovery. You can adopt an existing Group Replication deployment as an InnoDB Cluster.

InnoDB ClusterSet 和 InnoDB Cluster 的设计旨在抽象和简化设置、管理、监控、恢复和修复复制组的流程。InnoDB ClusterSet 使用专用的 ClusterSet 复制通道自动管理从主集群到副本集群的复制。如果主集群无法正常工作,您可以使用管理员命令在组之间触发受控切换或紧急故障转移。在初始设置之后,当需求发生变化时,服务器和组可以轻松地添加到或从 InnoDB ClusterSet 部署中移除。更多信息,请参见 MySQL InnoDB ClusterSet。InnoDB ClusterSet and InnoDB Cluster are designed to abstract and simplify the procedures for setting up, managing, monitoring, recovering, and repairing replication groups. InnoDB ClusterSet automatically manages replication from a primary cluster to replica clusters using a dedicated ClusterSet replication channel. You can use administrator commands to trigger a controlled switchover or emergency failover between groups if the primary cluster is not functioning normally. Servers and groups can easily be added to or removed from the InnoDB ClusterSet deployment after the initial setup when demand changes. For more information, see MySQL InnoDB ClusterSet.