文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 25 MySQL NDB 集群 8.4 / 25.7 NDB 集群复制 / 25.7.6 启动 NDB Cluster 复制(单复制通道)
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

25.7.6 启动 NDB 集群复制(单复制通道)25.7.6 Starting NDB Cluster Replication (Single Replication Channel)

本节概述了使用单复制通道启动 NDB 集群复制的步骤。This section outlines the procedure for starting NDB Cluster replication using a single replication channel.

  1. 通过执行以下命令启动 MySQL 复制源服务器,其中 id 是该服务器的唯一 ID(参见 第 25.7.2 节,“NDB 集群复制的一般要求”):Start the MySQL replication source server by issuing this command, where id is this server's unique ID (see Section 25.7.2, “General Requirements for NDB Cluster Replication”):

    shellS> mysqld --ndbcluster --server-id=id \
            --log-bin --ndb-log-bin &
    

    这会以启用二进制日志记录的方式启动服务器的 mysqld 进程,并使用适当的日志格式。同时,还需要显式启用对 NDB 表的更新日志记录,可使用 --ndb-log-bin 选项。This starts the server's mysqld process with binary logging enabled using the proper logging format. It is also necessary to enable logging of updates to NDB tables explicitly, using the --ndb-log-bin option.

    Note

    你也可以使用 --binlog-format=MIXED 来启动源服务器,在这种情况下,在集群之间复制时会自动使用基于行的复制。NDB 集群复制不支持基于语句的二进制日志(参见 第 25.7.2 节,“NDB 集群复制的一般要求”)。You can also start the source with --binlog-format=MIXED, in which case row-based replication is used automatically when replicating between clusters. Statement-based binary logging is not supported for NDB Cluster Replication (see Section 25.7.2, “General Requirements for NDB Cluster Replication”).

  2. 如下所示启动 MySQL 复制服务器:Start the MySQL replica server as shown here:

    shellR> mysqld --ndbcluster --server-id=id &
    

    在刚才显示的命令中,id 是复制服务器的唯一 ID。无需在复制服务器上启用日志记录。In the command just shown, id is the replica server's unique ID. It is not necessary to enable logging on the replica.

    Note

    除非您希望复制立即开始,否则请延迟复制线程的启动,直到已发出适当的 START REPLICA 语句,如下面步骤 4 中所述。您可以通过使用 --skip-replica-start 启动副本来实现这一点。Unless you want replication to begin immediately, delay the start of the replication threads until the appropriate START REPLICA statement has been issued, as explained in Step 4 below. You can do this by starting the replica with --skip-replica-start.

  3. 有必要将副本服务器与源服务器的复制二进制日志同步。如果源服务器之前未启用二进制日志,请在副本服务器上运行以下语句:It is necessary to synchronize the replica server with the source server's replication binary log. If binary logging has not previously been running on the source, run the following statement on the replica:

    mysqlR> CHANGE REPLICATION SOURCE TO
         -> SOURCE_LOG_FILE='',
         -> SOURCE_LOG_POS=4;
    

    这会指示从库从源服务器的二进制日志的起始点开始读取日志。否则——也就是说,如果您是通过备份从源加载数据——请参见第 25.7.8 节,“使用 NDB 集群复制实现故障切换”,了解在这种情况下如何获取用于SOURCE_LOG_FILE和SOURCE_LOG_POS的正确值。This instructs the replica to begin reading the source server's binary log from the log's starting point. Otherwise—that is, if you are loading data from the source using a backup—see Section 25.7.8, “Implementing Failover with NDB Cluster Replication”, for information on how to obtain the correct values to use for SOURCE_LOG_FILE and SOURCE_LOG_POS in such cases.

  4. 最后,通过从从库上的mysql客户端发出以下命令,指示从库开始应用复制:Finally, instruct the replica to begin applying replication by issuing this command from the mysql client on the replica:

    mysqlR> START REPLICA;

    这也会启动源到从库的数据和更改传输。This also initiates the transmission of data and changes from the source to the replica.

也可以使用两个复制通道,其方式类似于下一节中描述的过程;使用两个复制通道与使用单个复制通道之间的差异,请参见第 25.7.7 节,“使用两个复制通道进行 NDB 集群复制”。It is also possible to use two replication channels, in a manner similar to the procedure described in the next section; the differences between this and using a single replication channel are covered in Section 25.7.7, “Using Two Replication Channels for NDB Cluster Replication”.

通过启用批量更新,也可以提高集群复制性能。这可以通过在副本的mysqld 进程上设置系统变量 replica_allow_batching 来实现。通常,更新会在接收后立即应用。然而,使用批量处理会导致更新以每次 32 KB 的批次应用;这可以导致更高的吞吐量和更少的 CPU 使用,特别是在单个更新相对较小时。It is also possible to improve cluster replication performance by enabling batched updates. This can be accomplished by setting the system variable replica_allow_batching on the replicas' mysqld processes. Normally, updates are applied as soon as they are received. However, the use of batching causes updates to be applied in batches of 32 KB each; this can result in higher throughput and less CPU usage, particularly where individual updates are relatively small.

Note

批量处理是基于每个周期工作的;属于多个事务的更新可以作为同一批次的一部分发送。Batching works on a per-epoch basis; updates belonging to more than one transaction can be sent as part of the same batch.

在一个纪元结束时,所有未完成的更新都会被应用,即使更新总量不足 32 KB。All outstanding updates are applied when the end of an epoch is reached, even if the updates total less than 32 KB.

批处理可以在运行时开启或关闭。要在运行时激活它,可以使用以下两条语句之一:Batching can be turned on and off at runtime. To activate it at runtime, you can use either of these two statements:

SET GLOBAL replica_allow_batching = 1;
SET GLOBAL replica_allow_batching = ON;

如果某个批处理引发问题(例如某条语句的效果似乎没有被正确复制),可以使用以下任一语句停用批处理:If a particular batch causes problems (such as a statement whose effects do not appear to be replicated correctly), batching can be deactivated using either of the following statements:

SET GLOBAL replica_allow_batching = 0;
SET GLOBAL replica_allow_batching = OFF;

您可以通过适当的SHOW VARIABLES语句检查当前是否正在使用批处理,例如:You can check whether batching is currently being used by means of an appropriate SHOW VARIABLES statement, like this one:

mysql> SHOW VARIABLES LIKE 'replica%';