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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 25 MySQL NDB 集群 8.4 / 25.7 NDB 集群复制 / 25.7.5 准备 NDB Cluster 进行复制
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

25.7.5 为 NDB 集群进行复制准备25.7.5 Preparing the NDB Cluster for Replication

为 NDB 集群进行复制准备包括以下步骤:Preparing the NDB Cluster for replication consists of the following steps:

  1. 检查所有 MySQL 服务器的版本兼容性(参见 第 25.7.2 节,“NDB 集群复制的一般要求”)。Check all MySQL servers for version compatibility (see Section 25.7.2, “General Requirements for NDB Cluster Replication”).

  2. 在源集群上使用具有相应权限的账户创建复制账户,可使用以下两个 SQL 语句:Create a replication account on the source Cluster with the appropriate privileges, using the following two SQL statements:

    mysqlS> CREATE USER 'replica_user'@'replica_host'
         -> IDENTIFIED BY 'replica_password';
    
    mysqlS> GRANT REPLICATION SLAVE ON *.*
         -> TO 'replica_user'@'replica_host';
    

    在前面的语句中,replica_user 是复制账户的用户名,replica_host 是副本的主机名或 IP 地址,replica_password 是为该账户分配的密码。In the previous statement, replica_user is the replication account user name, replica_host is the host name or IP address of the replica, and replica_password is the password to assign to this account.

    例如,要创建一个名为 myreplica 的复制用户账户,从名为 replica-host 的主机登录,并使用密码 53cr37,请使用以下 CREATE USER 和 GRANT 语句:For example, to create a replica user account with the name myreplica, logging in from the host named replica-host, and using the password 53cr37, use the following CREATE USER and GRANT statements:

    mysqlS> CREATE USER 'myreplica'@'replica-host'
         -> IDENTIFIED BY '53cr37';
    
    mysqlS> GRANT REPLICATION SLAVE ON *.*
         -> TO 'myreplica'@'replica-host';
    

    出于安全原因,最好为复制账户使用唯一的用户账户——不要用于任何其他目的。For security reasons, it is preferable to use a unique user account—not employed for any other purpose—for the replication account.

  3. 设置副本以使用源。使用 mysql 客户端,可以通过 CHANGE REPLICATION SOURCE TO 语句来完成: Set up the replica to use the source. Using the mysql client, this can be accomplished with the CHANGE REPLICATION SOURCE TO statement:

    mysqlR> CHANGE REPLICATION SOURCE TO
         -> SOURCE_HOST='source_host',
         -> SOURCE_PORT=source_port,
         -> SOURCE_USER='replica_user',
         -> SOURCE_PASSWORD='replica_password';
    

    在前述语句中,source_host 是复制源的主机名或 IP 地址,source_port 是副本连接到源时使用的端口,replica_user 是在源上为副本设置的用户名,而 replica_password 是在前一步中为该用户帐户设置的密码。In the previous statement, source_host is the host name or IP address of the replication source, source_port is the port for the replica to use when connecting to the source, replica_user is the user name set up for the replica on the source, and replica_password is the password set for that user account in the previous step.

    例如,要告诉副本使用主机名为rep-source的 MySQL 服务器,并使用在上一步创建的复制账户,请使用以下语句:For example, to tell the replica to use the MySQL server whose host name is rep-source with the replication account created in the previous step, use the following statement:

    mysqlR> CHANGE REPLICATION SOURCE TO
         -> SOURCE_HOST='rep-source',
         -> SOURCE_PORT=3306,
         -> SOURCE_USER='myreplica',
         -> SOURCE_PASSWORD='53cr37';
    

    有关此语句中可使用的完整选项列表,请参阅 第 15.4.2.2 节,“CHANGE REPLICATION SOURCE TO 语句”。For a complete list of options that can be used with this statement, see Section 15.4.2.2, “CHANGE REPLICATION SOURCE TO Statement”.

    为了提供复制备份功能,您还需要在启动复制过程之前,在从库的my.cnf文件中添加--ndb-connectstring选项。详情请参见第 25.7.9 节,“使用 NDB 集群复制的 NDB 集群备份”。To provide replication backup capability, you also need to add an --ndb-connectstring option to the replica's my.cnf file prior to starting the replication process. See Section 25.7.9, “NDB Cluster Backups With NDB Cluster Replication”, for details.

    有关可以在从库的my.cnf中设置的其他选项,请参见第 19.1.6 节,“复制和二进制日志选项及变量”。For additional options that can be set in my.cnf for replicas, see Section 19.1.6, “Replication and Binary Logging Options and Variables”.

  4. 如果源集群已经在使用中,您可以创建源的备份,并将其加载到副本上,以减少副本与源同步所需的时间。如果副本也运行 NDB 集群,可以使用在第 25.7.9 节,“使用 NDB 集群复制的 NDB 集群备份” 中描述的备份和恢复过程来实现这一点。If the source cluster is already in use, you can create a backup of the source and load this onto the replica to cut down on the amount of time required for the replica to synchronize itself with the source. If the replica is also running NDB Cluster, this can be accomplished using the backup and restore procedure described in Section 25.7.9, “NDB Cluster Backups With NDB Cluster Replication”.

    ndb-connectstring=management_host[:port]
    

    如果您在副本上未使用 NDB 集群,可以在源上使用此命令创建备份:In the event that you are not using NDB Cluster on the replica, you can create a backup with this command on the source:

    shellS> mysqldump --source-data=1
    

    然后通过将数据转储文件复制到副本上来导入生成的数据转储文件。之后,您可以使用 mysql 客户端将转储文件中的数据导入到副本数据库,如下所示,其中 dump_file 是在源端使用 mysqldump 生成的文件名,db_name 是要复制的数据库名称:Then import the resulting data dump onto the replica by copying the dump file over to it. After this, you can use the mysql client to import the data from the dumpfile into the replica database as shown here, where dump_file is the name of the file that was generated using mysqldump on the source, and db_name is the name of the database to be replicated:

    shellR> mysql -u root -p db_name < dump_file
    

    有关 mysqldump 可用选项的完整列表,请参阅 第 6.5.4 节,“mysqldump — 数据库备份程序”。For a complete list of options to use with mysqldump, see Section 6.5.4, “mysqldump — A Database Backup Program”.

    Note

    如果以这种方式将数据复制到副本,请确保在所有数据加载完成之前,阻止副本尝试连接源以开始复制。可以通过使用 --skip-replica-start 启动副本来实现。数据加载完成后,请按照接下来两个部分中概述的附加步骤进行操作。If you copy the data to the replica in this fashion, make sure that you stop the replica from trying to connect to the source to begin replicating before all the data has been loaded. You can do this by starting the replica with --skip-replica-start. Once the data loading has completed, follow the additional steps outlined in the next two sections.

  5. 确保每个作为复制源的 MySQL 服务器都分配了唯一的服务器 ID,并启用了基于行的二进制日志记录。(参见 第 19.2.1 节,“复制格式”。)此外,我们强烈建议启用 replica_allow_batching 系统变量(默认值)。Ensure that each MySQL server acting as a replication source is assigned a unique server ID, and has binary logging enabled, using the row-based format. (See Section 19.2.1, “Replication Formats”.) In addition, we strongly recommend enabling the replica_allow_batching system variable (the default).

    使用 --ndb-replica-batch-size 来设置副本写操作的批量大小,而不是使用 --ndb-batch-size,以及使用 --ndb-replica-blob-write-batch-bytes 来代替 --ndb-blob-write-batch-bytes 以确定复制应用程序用于写入 BLOB 数据的批量大小。所有这些选项都可以在源服务器的 my.cnf 文件中设置,或者在启动源 mysqld 进程时通过命令行设置。更多信息,请参见 第 25.7.6 节,“启动 NDB 集群复制(单复制通道)”。Use --ndb-replica-batch-size to set the batch size used for writes on the replica instead of --ndb-batch-size, and --ndb-replica-blob-write-batch-bytes rather than --ndb-blob-write-batch-bytes to determine the batch size used by the replication applier for writing blob data. All of these options can be set either in the source server's my.cnf file, or on the command line when starting the source mysqld process. See Section 25.7.6, “Starting NDB Cluster Replication (Single Replication Channel)”, for more information.