13.4.2.3 CHANGE REPLICATION SOURCE TO Statement语句

CHANGE REPLICATION SOURCE TO option [, option] ... [ channel_option ]
option: {
    SOURCE_BIND = 'interface_name'
  | SOURCE_HOST = 'host_name'
  | SOURCE_USER = 'user_name'
  | SOURCE_PASSWORD = 'password'
  | SOURCE_PORT = port_num
  | PRIVILEGE_CHECKS_USER = {'account' | NULL}
  | REQUIRE_ROW_FORMAT = {0|1}
  | REQUIRE_TABLE_PRIMARY_KEY_CHECK = {STREAM | ON | OFF}
  | ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS = {OFF | LOCAL | uuid}
  | SOURCE_LOG_FILE = 'source_log_name'
  | SOURCE_LOG_POS = source_log_pos
  | SOURCE_AUTO_POSITION = {0|1}
  | RELAY_LOG_FILE = 'relay_log_name'
  | RELAY_LOG_POS = relay_log_pos
  | SOURCE_HEARTBEAT_PERIOD = interval
  | SOURCE_CONNECT_RETRY = interval
  | SOURCE_RETRY_COUNT = count
  | SOURCE_CONNECTION_AUTO_FAILOVER = {0|1}
  | SOURCE_DELAY = interval
  | SOURCE_COMPRESSION_ALGORITHMS = 'value'
  | SOURCE_ZSTD_COMPRESSION_LEVEL = level
  | SOURCE_SSL = {0|1}
  | SOURCE_SSL_CA = 'ca_file_name'
  | SOURCE_SSL_CAPATH = 'ca_directory_name'
  | SOURCE_SSL_CERT = 'cert_file_name'
  | SOURCE_SSL_CRL = 'crl_file_name'
  | SOURCE_SSL_CRLPATH = 'crl_directory_name'
  | SOURCE_SSL_KEY = 'key_file_name'
  | SOURCE_SSL_CIPHER = 'cipher_list'
  | SOURCE_SSL_VERIFY_SERVER_CERT = {0|1}
  | SOURCE_TLS_VERSION = 'protocol_list'
  | SOURCE_TLS_CIPHERSUITES = 'ciphersuite_list'
  | SOURCE_PUBLIC_KEY_PATH = 'key_file_name'
  | GET_SOURCE_PUBLIC_KEY = {0|1}
  | NETWORK_NAMESPACE = 'namespace'
  | IGNORE_SERVER_IDS = (server_id_list)
}
channel_option:
    FOR CHANNEL channel
server_id_list:
    [server_id [, server_id] ... ]

CHANGE REPLICATION SOURCE TO changes the parameters that the replica server uses for connecting to the source and for reading data from the source. CHANGE REPLICATION SOURCE TO更改副本服务器用于连接到源和从源读取数据的参数。It also updates the contents of the replication metadata repositories (see Section 17.2.4, “Relay Log and Replication Metadata Repositories”). 它还更新复制元数据存储库的内容(请参阅第17.2.4节,“中继日志和复制元数据存储库”)。From MySQL 8.0.23, use CHANGE REPLICATION SOURCE TO in place of CHANGE MASTER TO, which is deprecated from that release. 在MySQL 8.0.23中,使用CHANGE REPLICATION SOURCE TO代替CHANGE MASTER TO,后者在该版本中已被弃用。In releases before MySQL 8.0.23, use CHANGE MASTER TO.在MySQL 8.0.23之前的版本中,使用CHANGE MASTER TO

You can issue CHANGE REPLICATION SOURCE TO statements on a running replica without first stopping it, depending on the states of the replication SQL thread and replication I/O thread. 根据复制SQL线程和复制I/O线程的状态,您可以在运行的复制副本上发出CHANGE REPLICATION SOURCE TO语句,而无需首先停止它。The rules governing such use are provided later in this section. 本节后面将提供有关此类使用的规则。CHANGE REPLICATION SOURCE TO requires the REPLICATION_SLAVE_ADMIN privilege (or the deprecated SUPER privilege).CHANGE REPLICATION SOURCE TO需要REPLICATION_SLAVE_ADMIN权限(或不推荐使用的SUPER权限)。

When using a multithreaded replica (in other words slave_parallel_workers is greater than 0), stopping the replica can cause gaps in the sequence of transactions that have been executed from the relay log, regardless of whether the replica was stopped intentionally or otherwise. 当使用多线程复制副本时(换句话说,slave_parallel_workers大于0),停止复制副本可能会导致从中继日志执行的事务序列中出现“间隙”,而不管复制副本是故意停止还是以其他方式停止的。When such gaps exist, issuing CHANGE REPLICATION SOURCE TO fails. 当存在此类间隙时,发出CHANGE REPLICATION SOURCE TO失败。The solution in this situation is to issue START REPLICA UNTIL SQL_AFTER_MTS_GAPS which ensures that the gaps are closed.这种情况下的解决方案是发出START REPLICA UNTIL SQL_AFTER_MTS_GAPS,这确保了间隔被关闭。

The optional FOR CHANNEL channel clause enables you to name which replication channel the statement applies to. 可选的FOR CHANNEL channel子句允许您命名语句应用于哪个复制通道。Providing a FOR CHANNEL channel clause applies the CHANGE REPLICATION SOURCE TO statement to a specific replication channel, and is used to add a new channel or modify an existing channel. 提供FOR CHANNEL channel子句将CHANGE REPLICATION SOURCE TO语句应用于特定复制通道,并用于添加新通道或修改现有通道。For example, to add a new channel called channel2:例如,要添加名为channel2的新通道,请执行以下操作:

CHANGE REPLICATION SOURCE TO SOURCE_HOST=host1, SOURCE_PORT=3002 FOR CHANNEL 'channel2'

If no clause is named and no extra channels exist, the statement applies to the default channel.如果未命名任何子句且不存在额外通道,则该语句将应用于默认通道。

When using multiple replication channels, if a CHANGE REPLICATION SOURCE TO statement does not name a channel using a FOR CHANNEL channel clause, an error occurs. 使用多个复制通道时,如果CHANGE REPLICATION SOURCE TO语句未使用FOR CHANNEL channel子句命名通道,则会发生错误。See Section 17.2.2, “Replication Channels” for more information.有关更多信息,请参阅第17.2.2节,“复制通道”

Values used for SOURCE_HOST and other CHANGE REPLICATION SOURCE TO options are checked for linefeed (\n or 0x0A) characters. 用于SOURCE_HOST和其他CHANGE REPLICATION SOURCE TO选项的值会被检查换行(\n0x0A)字符。The presence of such characters in these values causes the statement to fail with ER_MASTER_INFO.这些值中存在这样的字符会导致该语句失败,并产生ER_MASTER_INFO错误。

Invoking CHANGE REPLICATION SOURCE TO causes the previous values for SOURCE_HOST, SOURCE_PORT, SOURCE_LOG_FILE, and SOURCE_LOG_POS to be written to the error log, along with other information about the replica's state prior to execution.调用CHANGE REPLICATION SOURCE TO可导致将SOURCE_HOSTSOURCE_PORTSOURCE_LOG_FILESOURCE_LOG_POS的先前值以及执行前副本状态的其他信息写入错误日志。

CHANGE REPLICATION SOURCE TO causes an implicit commit of an ongoing transaction. CHANGE REPLICATION SOURCE TO导致正在进行的事务的隐式提交。See Section 13.3.3, “Statements That Cause an Implicit Commit”.请参阅第13.3.3节,“导致隐式提交的语句”

For some of the options of the CHANGE REPLICATION SOURCE TO statement, you must issue a STOP REPLICA statement prior to issuing a CHANGE REPLICATION SOURCE TO statement (and a START REPLICA statement afterwards). 对于CHANGE REPLICATION SOURCE TO语句的某些选项,必须在发出CHANGE REPLICATION SOURCE TO语句之前发出STOP REPLICA语句(之后发出START REPLICA语句)。Sometimes, you only need to stop the replication SQL thread or the replication I/O thread, not both:有时,您只需要停止复制SQL线程或复制I/O线程,而不是同时停止这两个线程:

You can check the current state of the replication SQL thread and replication I/O thread using SHOW REPLICA STATUS. 您可以使用SHOW REPLICA STATUS查复制SQL线程和复制I/O线程的当前状态。Note that the Group Replication applier channel (group_replication_applier) has no I/O thread, only an SQL thread.请注意,组复制应用程序通道(group_replication_applier)没有I/O线程,只有一个SQL线程。

For more information, see Section 17.4.8, “Switching Sources During Failover”.有关更多信息,请参阅第17.4.8节,“故障切换期间切换源”

If you are using statement-based replication and temporary tables, it is possible for a CHANGE REPLICATION SOURCE TO statement following a STOP REPLICA statement to leave behind temporary tables on the replica. 如果您使用的是基于语句的复制和临时表,则在STOP REPLICA语句之后的CHANGE REPLICATION SOURCE TO语句可能会在副本上留下临时表。A warning (ER_WARN_OPEN_TEMP_TABLES_MUST_BE_ZERO) is now issued whenever this occurs. 无论何时发生这种情况,都会发出警告(ER_WARN_OPEN_TEMP_TABLES_MUST_BE_ZERO)。You can avoid this in such cases by making sure that the value of the Slave_open_temp_tables system status variable is equal to 0 prior to executing such a CHANGE REPLICATION SOURCE TO statement.在执行这种CHANGE REPLICATION SOURCE TO语句之前,可以通过确保系统状态变量Slave_open_temp_tables的值等于0来避免这种情况。

CHANGE REPLICATION SOURCE TO is useful for setting up a replica when you have the snapshot of the source and have recorded the source's binary log coordinates corresponding to the time of the snapshot. 当您拥有源的快照并记录了与快照时间相对应的源的二进制日志坐标时,CHANGE REPLICATION SOURCE TO可用于设置复制副本。After loading the snapshot into the replica to synchronize it with the source, you can run CHANGE REPLICATION SOURCE TO SOURCE_LOG_FILE='log_name', SOURCE_LOG_POS=log_pos on the replica to specify the coordinates at which the replica should begin reading the source's binary log.将快照加载到复制副本中以使其与源同步后,可以在复制副本上运行将复制源更改为CHANGE REPLICATION SOURCE TO SOURCE_LOG_FILE='log_name', SOURCE_LOG_POS=log_pos,以指定复制副本开始读取源二进制日志的坐标。

The following example changes the source server the replica uses and establishes the source's binary log coordinates from which the replica begins reading:以下示例更改复制副本使用的源服务器,并建立复制副本开始读取的源二进制日志坐标:

CHANGE REPLICATION SOURCE TO
  SOURCE_HOST='source2.example.com',
  SOURCE_USER='replication',
  SOURCE_PASSWORD='password',
  SOURCE_PORT=3306,
  SOURCE_LOG_FILE='source2-bin.001',
  SOURCE_LOG_POS=4,
  SOURCE_CONNECT_RETRY=10;

The next example shows an operation that is less frequently employed. 下一个示例显示了一个较少使用的操作。It is used when the replica has relay log files that you want it to execute again for some reason. 当复制副本中有中继日志文件,您希望出于某种原因再次执行该文件时,将使用该日志文件。To do this, the source need not be reachable. 为此,不需要访问源。You need only use CHANGE REPLICATION SOURCE TO and start the SQL thread (START REPLICA SQL_THREAD):您只需使用CHANGE REPLICATION SOURCE TO并启动SQL线程(START REPLICA SQL_THREAD):

CHANGE REPLICATION SOURCE TO
  RELAY_LOG_FILE='replica-relay-bin.006',
  RELAY_LOG_POS=4025;

Options that you do not specify on a CHANGE REPLICATION SOURCE TO statement retain their value, except as indicated in the following discussion. 除非在下面的讨论中指出,否则在CHANGE REPLICATION SOURCE TO语句中未指定的选项将保留其值。Thus, in most cases, there is no need to specify options that do not change.因此,在大多数情况下,不需要指定不变的选项。

ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS

Makes the replication channel assign a GTID to replicated transactions that do not have one, enabling replication from a source that does not use GTID-based replication, to a replica that does. 使复制通道将GTID分配给没有GTID的复制事务,从而允许从不使用基于GTID的复制的源复制到使用GTID的复制副本。For a multi-source replica, you can have a mix of channels that use ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS, and channels that do not. 对于多源复制副本,可以混合使用ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS和不使用ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS的通道。The default is OFF, meaning that the feature is not used.默认值为OFF,表示不使用该功能。

LOCAL assigns a GTID including the replica's own UUID (the server_uuid setting). LOCAL分配一个GTID,包括复制副本自己的UUID(服务器UUID设置)。uuid assigns a GTID including the specified UUID, such as the server_uuid setting for the replication source server. uuid分配一个包含指定uuid的GTID,例如复制源服务器的服务器uuid设置。Using a nonlocal UUID lets you differentiate between transactions that originated on the replica and transactions that originated on the source, and for a multi-source replica, between transactions that originated on different sources. 使用非本地UUID,可以区分源于副本的事务和源上的事务,对于多源副本,可以区分源于不同源上的事务。The UUID you choose only has significance for the replica's own use. 您选择的UUID仅对副本的自身使用具有重要意义。If any of the transactions sent by the source do have a GTID already, that GTID is retained.如果源发送的任何事务已经有GTID,则保留该GTID。

Channels specific to Group Replication cannot use ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS, but an asynchronous replication channel for another source on a server instance that is a Group Replication group member can do so. 特定于组复制的通道不能使用ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS,但作为组复制组成员的服务器实例上另一个源的异步复制通道可以这样做。In that case, do not specify the Group Replication group name as the UUID for creating the GTIDs.在这种情况下,不要将组复制组名称指定为用于创建GTID的UUID。

To set ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS to LOCAL or uuid, the replica must have gtid_mode=ON set, and this cannot be changed afterwards. 要将ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS设置为LOCALuuid,复制副本必须设置gtid_mode=ON,并且以后不能更改。This option is for use with a source that has binary log file position based replication, so MASTER_AUTO_POSITION=1 cannot be set for the channel. 此选项用于具有基于二进制日志文件位置的复制的源,因此无法为通道设置MASTER_AUTO_POSITION=1Both the replication SQL thread and the replication I/O thread must be stopped before setting this option.在设置此选项之前,必须停止复制SQL线程和复制I/O线程。

Important重要

A replica set up with ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS on any channel cannot be promoted to replace the replication source server in the event that a failover is required, and a backup taken from the replica cannot be used to restore the replication source server. 在需要故障切换的情况下,在任何通道上使用ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS设置的复制副本无法升级以替换复制源服务器,并且从复制副本获取的备份不能用于恢复复制源服务器。The same restriction applies to replacing or restoring other replicas that use ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS on any channel.同样的限制也适用于替换或恢复在任何通道上使用ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS的其他副本。

For further restrictions and information, see Section 17.1.3.6, “Replication From a Source Without GTIDs to a Replica With GTIDs”.有关更多限制和信息,请参阅第17.1.3.6节,“从没有GTID的源复制到具有GTID的副本”

GET_SOURCE_PUBLIC_KEY

Enables RSA key pair-based password exchange by requesting the public key from the source. 通过从源请求公钥,启用基于RSA密钥对的密码交换。This option applies to replicas that authenticate with the caching_sha2_password authentication plugin. 此选项适用于使用caching_sha2_password身份验证插件进行身份验证的副本。For connections by accounts that authenticate using this plugin, the source does not send the public key unless requested, so it must be requested or specified in the client. 对于使用此插件进行身份验证的帐户连接,除非请求,否则源不会发送公钥,因此必须在客户端请求或指定公钥。If SOURCE_PUBLIC_KEY_PATH is given and specifies a valid public key file, it takes precedence over GET_SOURCE_PUBLIC_KEY. 如果给定SOURCE_PUBLIC_KEY_PATH并指定了有效的公钥文件,则该路径优先于GET_SOURCE_PUBLIC_KEYIf you are using a replication user account that authenticates with the caching_sha2_password plugin (which is the default from MySQL 8.0), and you are not using a secure connection, you must specify either this option or the SOURCE_PUBLIC_KEY_PATH option to provide the RSA public key to the replica.如果您使用的复制用户帐户使用caching_sha2_password插件(MySQL 8.0中的默认插件)进行身份验证,并且您没有使用安全连接,则必须指定此选项或SOURCE_PUBLIC_KEY_PATH选项以向复制副本提供RSA公钥。

IGNORE_SERVER_IDS

Makes the replica ignore events originating from the specified servers. 使复制副本忽略源自指定服务器的事件。The option takes a comma-separated list of 0 or more server IDs. 该选项采用逗号分隔的0个或多个服务器ID列表。Log rotation and deletion events from the servers are not ignored, and are recorded in the relay log.服务器的日志旋转和删除事件不会被忽略,并记录在中继日志中。

In circular replication, the originating server normally acts as the terminator of its own events, so that they are not applied more than once. 在循环复制中,发起服务器通常充当其自身事件的终止器,因此不会多次应用这些事件。Thus, this option is useful in circular replication when one of the servers in the circle is removed. 因此,当删除循环中的一个服务器时,此选项在循环复制中非常有用。Suppose that you have a circular replication setup with 4 servers, having server IDs 1, 2, 3, and 4, and server 3 fails. 假设您有一个包含4台服务器的循环复制设置,服务器ID为1、2、3和4,而服务器3出现故障。When bridging the gap by starting replication from server 2 to server 4, you can include IGNORE_SERVER_IDS = (3) in the CHANGE REPLICATION SOURCE TO statement that you issue on server 4 to tell it to use server 2 as its source instead of server 3. 当通过启动从服务器2到服务器4的复制来缩小差距时,您可以在服务器4上发出的CHANGE REPLICATION SOURCE TO语句中包含IGNORE_SERVER_IDS = (3),以告知它使用服务器2作为其源,而不是服务器3。Doing so causes it to ignore and not to propagate any statements that originated with the server that is no longer in use.这样做会导致它忽略并且不会传播任何源于不再使用的服务器的语句。

If IGNORE_SERVER_IDS contains the server's own ID and the server was started with the --replicate-same-server-id option enabled, an error results.如果IGNORE_SERVER_IDS包含服务器自己的ID,并且服务器启动时启用了--replicate-same-server-id选项,则会导致错误。

Note注意

When global transaction identifiers (GTIDs) are used for replication, transactions that have already been applied are automatically ignored, so the IGNORE_SERVER_IDS function is not required and is deprecated. 当全局事务标识符(GTID)用于复制时,已应用的事务将自动忽略,因此不需要使用IGNORE_SERVER_IDS功能,因此不推荐使用该功能。If gtid_mode=ON is set for the server, a deprecation warning is issued if you include the IGNORE_SERVER_IDS option in a CHANGE REPLICATION SOURCE TO statement.如果为服务器设置了gtid_mode=ON,则如果在CHANGE REPLICATION SOURCE TO语句中包含IGNORE_SERVER_IDS选项,将发出弃用警告。

The source metadata repository and the output of SHOW REPLICA STATUS provide the list of servers that are currently ignored. 源元数据存储库和SHOW REPLICA STATUS的输出提供了当前被忽略的服务器的列表。For more information, see Section 17.2.4.2, “Replication Metadata Repositories”, and Section 13.7.7.35, “SHOW REPLICA | SLAVE STATUS Statement”.有关更多信息,请参阅第17.2.4.2节,“复制元数据存储库”第13.7.7.35节,“SHOW REPLICA | SLAVE STATUS语句”

If a CHANGE REPLICATION SOURCE TO statement is issued without any IGNORE_SERVER_IDS option, any existing list is preserved. 如果在没有任何IGNORE_SERVER_IDS选项的情况下发出CHANGE REPLICATION SOURCE TO语句,则会保留任何现有列表。To clear the list of ignored servers, it is necessary to use the option with an empty list:要清除被忽略服务器的列表,必须使用空列表选项:

CHANGE REPLICATION SOURCE TO IGNORE_SERVER_IDS = ();

RESET REPLICA ALL clears IGNORE_SERVER_IDS.RESET REPLICA ALL清除IGNORE_SERVER_IDS

Note注意

A deprecation warning is issued if SET GTID_MODE=ON is issued when any channel has existing server IDs set with IGNORE_SERVER_IDS. 如果在任何通道的现有服务器ID设置为IGNORE_SERVER_IDS时发出SET GTID_MODE=ON,则会发出弃用警告。Before starting GTID-based replication, check for and clear all ignored server ID lists on the servers involved. 在启动基于GTID的复制之前,请检查并清除相关服务器上所有被忽略的服务器ID列表。The SHOW REPLICA STATUS statement displays the list of ignored IDs, if there is one. SHOW REPLICA STATUS语句显示被忽略ID的列表(如果有)。If you do receive the deprecation warning, you can still clear a list after gtid_mode=ON is set by issuing a CHANGE REPLICATION SOURCE TO statement containing the IGNORE_SERVER_IDS option with an empty list.如果您确实收到了弃用警告,则在设置gtid_mode=ON后,您仍然可以通过发出包含带有空列表的IGNORE_SERVER_IDS选项的CHANGE REPLICATION SOURCE TO语句来清除列表。

NETWORK_NAMESPACE

The network namespace to use for TCP/IP connections to the replication source server. 用于到复制源服务器的TCP/IP连接的网络命名空间。If this option is omitted, connections from the replica use the default (global) namespace. 如果省略此选项,则来自复制副本的连接将使用默认(全局)命名空间。On platforms that do not implement network namespace support, failure occurs when the replica attempts to connect to the source. 在未实现网络命名空间支持的平台上,复制副本尝试连接到源时会发生故障。For information about network namespaces, see Section 5.1.14, “Network Namespace Support”. 有关网络名称空间的信息,请参阅第5.1.14节,“网络名称空间支持”NETWORK_NAMESPACE is available as of MySQL 8.0.22.NETWORK_NAMESPACE从MySQL 8.0.22开始可用。

PRIVILEGE_CHECKS_USER

Names a user account that supplies a security context for the specified channel. 命名为指定通道提供安全上下文的用户帐户。NULL, which is the default, means no security context is used. NULL是默认值,表示未使用安全上下文。PRIVILEGE_CHECKS_USER is available as of MySQL 8.0.18.PRIVILEGE_CHECKS_USER从MySQL 8.0.18开始可用。

The user name and host name for the user account must follow the syntax described in Section 6.2.4, “Specifying Account Names”, and the user must not be an anonymous user (with a blank user name) or the CURRENT_USER. 用户帐户的用户名和主机名必须遵循第6.2.4节,“指定帐户名”中描述的语法,并且用户不得是匿名用户(用户名为空)或CURRENT_USERThe account must have the REPLICATION_APPLIER privilege, plus the required privileges to execute the transactions replicated on the channel. 该帐户必须具有REPLICATION_APPLIER(复制应用程序)权限,以及执行在通道上复制的事务所需的权限。For details of the privileges required by the account, see Section 17.3.3, “Replication Privilege Checks”. 有关帐户所需权限的详细信息,请参阅第17.3.3节,“复制权限检查”When you restart the replication channel, the privilege checks are applied from that point on. If you do not specify a channel and no other channels exist, the statement is applied to the default channel.重新启动复制通道时,将从此点开始应用权限检查。如果未指定通道且不存在其他通道,则该语句将应用于默认通道。

The use of row-based binary logging is strongly recommended when PRIVILEGE_CHECKS_USER is set, and you can set REQUIRE_ROW_FORMAT to enforce this. 当设置了PRIVILEGE_CHECKS_USER时,强烈建议使用基于行的二进制日志记录,您可以设置REQUIRE_ROW_FORMAT来强制执行此操作。For example, to start privilege checks on the channel channel_1 on a running replica, issue the following statements:例如,要对正在运行的复制副本上的channel_1启动权限检查,请发出以下语句:

mysql> STOP REPLICA FOR CHANNEL 'channel_1';
mysql> CHANGE REPLICATION SOURCE TO
         PRIVILEGE_CHECKS_USER = 'priv_repl'@'%.example.com',
         REQUIRE_ROW_FORMAT = 1,
         FOR CHANNEL 'channel_1';
mysql> START REPLICA FOR CHANNEL 'channel_1';
RELAY_LOG_FILE, RELAY_LOG_POS

The relay log file name, and the location in that file, at which the replication SQL thread begins reading from the replica's relay log the next time the thread starts. 中继日志文件名以及该文件中的位置,在该位置,复制SQL线程在下次线程启动时开始从副本的中继日志中读取数据。RELAY_LOG_FILE can use either an absolute or relative path, and uses the same base name as SOURCE_LOG_FILE.RELAY_LOG_FILE可以使用绝对路径或相对路径,并使用与SOURCE_LOG_FILE相同的基本名称。

A CHANGE REPLICATION SOURCE TO statement using RELAY_LOG_FILE, RELAY_LOG_POS, or both options can be executed on a running replica when the replication SQL thread is stopped. 当复制SQL线程停止时,可以在正在运行的复制副本上执行使用RELAY_LOG_FILE选项、RELAY_LOG_POS选项或同时使用这两个选项的CHANGE REPLICATION SOURCE TO语句。Relay logs are preserved if at least one of the replication SQL thread and the replication I/O thread is running. 如果至少有一个复制SQL线程和复制I/O线程正在运行,则会保留中继日志。If both threads are stopped, all relay log files are deleted unless at least one of RELAY_LOG_FILE or RELAY_LOG_POS is specified. 如果两个线程都停止,则删除所有中继日志文件,除非至少指定了RELAY_LOG_FILERELAY_LOG_POS中的一个。For the Group Replication applier channel (group_replication_applier), which only has an SQL thread and no I/O thread, this is the case if the SQL thread is stopped, but with that channel you cannot use the RELAY_LOG_FILE and RELAY_LOG_POS options.对于只有一个SQL线程而没有I/O线程的组复制应用程序通道(group_replication_applier),如果SQL线程停止,则会出现这种情况,但对于该通道,您不能使用RELAY_LOG_FILERELAY_LOG_POS选项。

REQUIRE_ROW_FORMAT

Permits only row-based replication events to be processed by the replication channel. 仅允许复制通道处理基于行的复制事件。This option prevents the replication applier from taking actions such as creating temporary tables and executing LOAD DATA INFILE requests, which increases the security of the channel. 此选项可防止复制应用程序执行创建临时表和执行LOAD DATA INFILE请求等操作,从而提高通道的安全性。Group Replication channels are automatically created with REQUIRE_ROW_FORMAT set, and you cannot change the option for those channels. 组复制通道是使用REQUIRE_ROW_FORMAT集自动创建的,您不能更改这些通道的选项。For more information, see Section 17.3.3, “Replication Privilege Checks”. 有关更多信息,请参阅第17.3.3节,“复制权限检查”REQUIRE_ROW_FORMAT is available as of MySQL 8.0.19.REQUIRE_ROW_FORMAT从MySQL 8.0.19开始可用。

REQUIRE_TABLE_PRIMARY_KEY_CHECK

Enables a replica to select its own policy for primary key checks. 使复制副本能够为主键检查选择自己的策略。When the option is set to ON for a replication channel, the replica always uses the value ON for the sql_require_primary_key system variable in replication operations, requiring a primary key. 当复制通道的选项设置为ON时,复制副本在复制操作中始终使用sql_require_primary_key系统变量的值ON,这需要一个主键。When the option is set to OFF, the replica always uses the value OFF for the sql_require_primary_key system variable in replication operations, so that a primary key is never required, even if the source required one. 当该选项设置为OFF时,复制副本在复制操作中始终使用系统变量sql_require_primary_key的值OFF,这样即使源需要主键,也不需要主键。When the REQUIRE_TABLE_PRIMARY_KEY_CHECK option is set to STREAM, which is the default, the replica uses whatever value is replicated from the source for each transaction. REQUIRE_TABLE_PRIMARY_KEY_CHECK选项设置为STREAM(默认设置)时,复制副本将使用从源为每个事务复制的任何值。REQUIRE_TABLE_PRIMARY_KEY_CHECK is available as of MySQL 8.0.20.REQUIRE_TABLE_PRIMARY_KEY_CHECK从MySQL 8.0.20开始可用。

For multisource replication, setting REQUIRE_TABLE_PRIMARY_KEY_CHECK to ON or OFF enables a replica to normalize behavior across the replication channels for different sources, and keep a consistent setting for the sql_require_primary_key system variable. 对于多源复制,将REQUIRE_TABLE_PRIMARY_KEY_CHECK设置为ONOFF可使复制副本跨复制通道规范化不同源的行为,并保持系统变量sql_require_primary_key的一致设置。Using ON safeguards against the accidental loss of primary keys when multiple sources update the same set of tables. 当多个源更新同一组表时,使用ON保护措施防止主键意外丢失。Using OFF allows sources that can manipulate primary keys to work alongside sources that cannot.使用OFF允许可以操纵主键的源与不能操纵主键的源一起工作。

When PRIVILEGE_CHECKS_USER is set, setting REQUIRE_TABLE_PRIMARY_KEY_CHECK to ON or OFF means that the user account does not need session administration level privileges to set restricted session variables, which are required to change the value of sql_require_primary_key to match the source's setting for each transaction. 设置PRIVILEGE_CHECKS_USER时,将REQUIRE_TABLE_PRIMARY_KEY_CHECK设置为ON或OFF意味着用户帐户不需要会话管理级别的特权来设置受限会话变量,这是更改sql_REQUIRE_PRIMARY_KEY的值以匹配每个事务的源设置所必需的。For more information, see Section 17.3.3, “Replication Privilege Checks”.有关更多信息,请参阅第17.3.3节,“复制权限检查”

SOURCE_AUTO_POSITION

Makes the replica attempt to connect to the source using the auto-positioning feature of GTID-based replication, rather than a binary log file based position. 使复制副本尝试使用基于GTID的复制的自动定位功能(而不是基于二进制日志文件的位置)连接到源。This option can be used with CHANGE REPLICATION SOURCE TO only if both the replication SQL thread and replication I/O thread are stopped.仅当复制SQL线程和复制I/O线程都停止时,此选项才能用于CHANGE REPLICATION SOURCE TO

Both the replica and the source must have GTIDs enabled (GTID_MODE=ON, ON_PERMISSIVE, or OFF_PERMISSIVE on the replica, and GTID_MODE=ON on the source). 副本和源都必须启用GTID(副本上的GTID_MODE=ONON_PERMISSIVEOFF_PERMISSIVE,源上的GTID_MODE=ON)。SOURCE_LOG_FILE, SOURCE_LOG_POS, RELAY_LOG_FILE, and RELAY_LOG_POS cannot be specified together with SOURCE_AUTO_POSITION = 1. SOURCE_LOG_FILESOURCE_LOG_POSRELAY_LOG_FILERELAY_LOG_POS不能与SOURCE_AUTO_POSITION = 1一起指定。If multi-source replication is enabled on the replica, you need to set the SOURCE_AUTO_POSITION = 1 option for each applicable replication channel.如果在复制副本上启用了多源复制,则需要为每个适用的复制通道设置SOURCE_AUTO_POSITION = 1选项。

With SOURCE_AUTO_POSITION = 1 set, in the initial connection handshake, the replica sends a GTID set containing the transactions that it has already received, committed, or both. SOURCE_AUTO_POSITION = 1时,在初始连接握手中,复制副本发送一个GTID集,其中包含它已经接收、提交或同时提交的事务。The source responds by sending all transactions recorded in its binary log whose GTID is not included in the GTID set sent by the replica. 源通过发送其二进制日志中记录的所有事务进行响应,这些事务的GTID不包括在副本发送的GTID集中。This exchange ensures that the source only sends the transactions with a GTID that the replica has not already recorded or committed. 此交换确保源仅发送带有GTID的事务,而复制副本尚未记录或提交该GTID。If the replica receives transactions from more than one source, as in the case of a diamond topology, the auto-skip function ensures that the transactions are not applied twice. 如果复制副本从多个源接收事务(如菱形拓扑),则自动跳过功能可确保事务不会应用两次。For details of how the GTID set sent by the replica is computed, see Section 17.1.3.3, “GTID Auto-Positioning”.有关如何计算副本发送的GTID集的详细信息,请参阅第17.1.3.3节,“GTID自动定位”

If any of the transactions that should be sent by the source have been purged from the source's binary log, or added to the set of GTIDs in the gtid_purged system variable by another method, the source sends the error ER_MASTER_HAS_PURGED_REQUIRED_GTIDS to the replica, and replication does not start. 如果源应发送的任何事务已从源的二进制日志中清除,或通过另一种方法添加到系统变量gtid_purged中的GTID集,则源将错误ER_MASTER_HAS_PURGED_REQUIRED_GTIDS发送到副本,并且复制不会启动。The GTIDs of the missing purged transactions are identified and listed in the source's error log in the warning message ER_FOUND_MISSING_GTIDS. 丢失的已清除事务的GTID被识别并列在警告消息ER_FOUND_MISSING_GTIDS的源错误日志中。Also, if during the exchange of transactions it is found that the replica has recorded or committed transactions with the source's UUID in the GTID, but the source itself has not committed them, the source sends the error ER_SLAVE_HAS_MORE_GTIDS_THAN_MASTER to the replica and replication does not start. 此外,如果在事务交换期间发现复制副本已在GTID中记录或提交了具有源UUID的事务,但源本身未提交这些事务,则源会向复制副本发送错误ER_SLAVE_HAS_MORE_GTIDS_THAN_MASTER,而且复制不会启动。For information on how to handle these situations, see Section 17.1.3.3, “GTID Auto-Positioning”.有关如何处理这些情况的信息,请参阅第17.1.3.3节,“GTID自动定位”

You can see whether replication is running with GTID auto-positioning enabled by checking the Performance Schema replication_connection_status table or the output of SHOW REPLICA STATUS. 通过检查性能架构replication_connection_status表或SHOW REPLICA STATUS的输出,可以查看复制是否在启用GTID自动定位的情况下运行。Disabling the SOURCE_AUTO_POSITION option again makes the replica revert to file-based replication.再次禁用SOURCE_AUTO_POSITION选项将使复制副本恢复为基于文件的复制。

SOURCE_BIND

Determines which of the replica's network interfaces is chosen for connecting to the source, for use on replicas that have multiple network interfaces. 确定选择哪个复制副本的网络接口连接到源,以便在具有多个网络接口的复制副本上使用。The address configured with this option, if any, can be seen in the Source_Bind column of the output from SHOW REPLICA STATUS. 使用此选项配置的地址(如果有)可以在SHOW REPLICA STATUS输出的Source_Bind列中看到。In the source metadata repository table mysql.slave_master_info, the value can be seen as the Source_bind column. 在源元数据存储库表mysql.slave_master_info中,该值可视为Source_bind列。The ability to bind a replica to a specific network interface is also supported by NDB Cluster.NDB群集还支持将副本绑定到特定网络接口的功能。

SOURCE_COMPRESSION_ALGORITHMS

Specifies the permitted compression algorithms for connections to the replication source server. 指定到复制源服务器的连接允许的压缩算法。The available algorithms are the same as for the protocol_compression_algorithms system variable. 可用算法与系统变量protocol_compression_algorithms相同。The default value is uncompressed. 默认值为uncompressedSOURCE_COMPRESSION_ALGORITHMS is available as of MySQL 8.0.18.SOURCE_COMPRESSION_ALGORITHMS(源代码压缩算法)从MySQL 8.0.18开始可用。

The value of SOURCE_COMPRESSION_ALGORITHMS applies only if the slave_compressed_protocol system variable is disabled. 仅当禁用系统变量slave_compressed_protocol时,SOURCE_COMPRESSION_ALGORITHMS的值才适用。If slave_compressed_protocol is enabled, it takes precedence over SOURCE_COMPRESSION_ALGORITHMS and connections to the source use zlib compression if both source and replica support that algorithm. 如果启用了slave_compressed_protocol,则其优先级高于SOURCE_COMPRESSION_ALGORITHMS,如果源和复制副本都支持该算法,则到源的连接将使用zlib压缩。For more information, see Section 4.2.8, “Connection Compression Control”.有关更多信息,请参阅第4.2.8节,“连接压缩控制”

Binary log transaction compression (available as of MySQL 8.0.20), which is activated by the binlog_transaction_compression system variable, can also be used to save bandwidth. 系统变量binlog_transaction_compression激活的二进制日志事务压缩(从MySQL 8.0.20开始提供)也可用于节省带宽。If you do this in combination with connection compression, connection compression has less opportunity to act on the data, but can still compress headers and those events and transaction payloads that are uncompressed. 如果将连接压缩与此结合使用,则连接压缩对数据的作用机会较小,但仍可以压缩头以及未压缩的事件和事务有效负载。For more information on binary log transaction compression, see Section 5.4.4.5, “Binary Log Transaction Compression”.有关二进制日志事务压缩的更多信息,请参阅第5.4.4.5节,“二进制日志事务压缩”

SOURCE_CONNECT_RETRY

Specifies the interval between the reconnection attempts that the replica makes after the connection to the source times out. 指定复制副本在与源的连接超时后进行的重新连接尝试之间的间隔。The attempts are limited by the SOURCE_RETRY_COUNT option. 尝试受SOURCE_RETRY_COUNT选项的限制。If both the default settings are used, the replica waits 60 seconds between reconnection attempts (SOURCE_CONNECT_RETRY=60), and keeps attempting to reconnect at this rate for 60 days (SOURCE_RETRY_COUNT=86400). 如果使用了这两种默认设置,则复制副本在两次重新连接尝试之间等待60秒(SOURCE_CONNECT_RETRY=60),并在60天内继续尝试以此速率重新连接(SOURCE_RETRY_COUNT=86400)。These values are recorded in the source metadata repository and shown in the replication_connection_configuration Performance Schema table.这些值记录在源元数据存储库中,并显示在replication_connection_configuration性能架构表中。

SOURCE_CONNECTION_AUTO_FAILOVER

Activates the asynchronous connection failover mechanism for a replication channel if one or more alternative replication source servers are available (so when there are multiple MySQL servers or groups of servers that share the replicated data). 如果有一个或多个备用复制源服务器可用(如果有多个MySQL服务器或共享复制数据的服务器组),则激活复制通道的异步连接故障切换机制。SOURCE_CONNECTION_AUTO_FAILOVER is available as of MySQL 8.0.22. 从MySQL 8.0.22开始,就可以使用SOURCE_CONNECTION_AUTO_FAILOVER(源连接自动故障转移)。The asynchronous connection failover mechanism takes over after the reconnection attempts controlled by SOURCE_CONNECT_RETRY and SOURCE_RETRY_COUNT are exhausted. 异步连接故障切换机制在SOURCE_CONNECT_RETRY(源连接重试)和SOURCE_RETRY_COUNT(源重试计数)控制的重新连接尝试用尽后接管。It reconnects the replica to an alternative source chosen from a specified source list, which you manage using the asynchronous_connection_failover_add_source and asynchronous_connection_failover_delete_source functions. 它将复制副本重新连接到从指定源列表中选择的备用源,您可以使用asynchronous_connection_failover_add_sourceasynchronous_connection_failover_delete_source功能对其进行管理。To add and remove managed groups of servers, use the asynchronous_connection_failover_add_managed and asynchronous_connection_failover_delete_managed functions instead. 若要添加和删除托管服务器组,请改用asynchronous_connection_failover_add_managedasynchronous_connection_failover_delete_managed功能。For more information, see Section 17.4.9, “Switching Sources with Asynchronous Connection Failover”.有关更多信息,请参阅第17.4.9节,“使用异步连接故障切换切换源”

Important重要
  1. You can only set SOURCE_CONNECTION_AUTO_FAILOVER = 1 when GTID auto-positioning is in use (SOURCE_AUTO_POSITION = 1).只有在使用GTID自动定位(SOURCE_AUTO_POSITION = 1)时,才能将SOURCE_CONNECTION_AUTO_FAILOVER = 1

  2. When you set SOURCE_CONNECTION_AUTO_FAILOVER = 1, set SOURCE_RETRY_COUNT and SOURCE_CONNECT_RETRY to minimal numbers that just allow a few retry attempts with the same source, in case the connection failure is caused by a transient network outage. 当您设置SOURCE_CONNECTION_AUTO_FAILOVER = 1时,请将SOURCE_RETRY_COUNTSOURCE_CONNECT_RETRY设置为允许对同一源进行几次重试尝试的最小值,以防连接失败是由暂时性网络中断引起的。Otherwise the asynchronous connection failover mechanism cannot be activated promptly. 否则,异步连接故障切换机制无法立即激活。Suitable values are SOURCE_RETRY_COUNT=3 and SOURCE_CONNECT_RETRY=10, which make the replica retry the connection 3 times with 10-second intervals between.合适的值是SOURCE_RETRY_COUNT=3SOURCE_CONNECT_RETRY=10,这使得复制副本以10秒的间隔重试连接3次。

  3. When you set SOURCE_CONNECTION_AUTO_FAILOVER = 1, the replication metadata repositories must contain the credentials for a replication user account that can be used to connect to all the servers on the source list for the replication channel. 当您设置SOURCE_CONNECTION_AUTO_FAILOVER = 1时,复制元数据存储库必须包含复制用户帐户的凭据,该帐户可用于连接到复制通道源列表上的所有服务器。The account must also have SELECT permissions on the Performance Schema tables. 该帐户还必须对性能架构表具有SELECT权限。These credentials can be set using the CHANGE REPLICATION SOURCE TO statement with the SOURCE_USER and SOURCE_PASSWORD options. 可以使用CHANGE REPLICATION SOURCE TO语句配合SOURCE_USERSOURCE_PASSWORD选项来设置这些凭据。For more information, see Section 17.4.9, “Switching Sources with Asynchronous Connection Failover”.有关更多信息,请参阅第17.4.9节,“使用异步连接故障切换切换源”

SOURCE_DELAY

Specifies how many seconds behind the source the replica must lag. 指定复制副本必须落后于源的秒数。An event received from the source is not executed until at least interval seconds later than its execution on the source. 从源接收的事件在源上执行至少interval秒后才会执行。The default is 0. 默认值为0。An error occurs if interval is not a nonnegative integer in the range from 0 to 231−1. 如果间隔不是0到231-1范围内的非负整数,则会发生错误。For more information, see Section 17.4.11, “Delayed Replication”. 有关更多信息,请参阅第17.4.11节,“延迟复制”A CHANGE REPLICATION SOURCE TO statement using the SOURCE_DELAY option can be executed on a running replica when the replication SQL thread is stopped.当复制SQL线程停止时,可以在正在运行的复制副本上执行使用SOURCE_DELAY选项的CHANGE REPLICATION SOURCE TO语句。

SOURCE_HEARTBEAT_PERIOD

Controls the heartbeat interval, which stops the connection timeout occurring in the absence of data if the connection is still good. 控制心跳间隔,如果连接仍然良好,则心跳间隔将停止在缺少数据的情况下发生的连接超时。A heartbeat signal is sent to the replica after that number of seconds, and the waiting period is reset whenever the source's binary log is updated with an event. 在该秒数之后,心跳信号被发送到复制副本,并且每当源的二进制日志被事件更新时,等待时间被重置。Heartbeats are therefore sent by the source only if there are no unsent events in the binary log file for a period longer than this.因此,只有在二进制日志文件中没有超过此时间段的未发送事件时,源才会发送心跳。

The heartbeat interval interval is a decimal value having the range 0 to 4294967 seconds and a resolution in milliseconds; the smallest nonzero value is 0.001. 心跳间隔interval是一个十进制值,范围为0到4294967秒,分辨率以毫秒为单位;最小非零值为0.001。Setting interval to 0 disables heartbeats altogether. interval设置为0将完全禁用心跳。The heartbeat interval defaults to half the value of the slave_net_timeout system variable. 心跳间隔默认为系统变量slave_net_timeout值的一半。It is recorded in the source metadata repository and shown in the replication_connection_configuration Performance Schema table. 它记录在源元数据存储库中,并显示在replication_connection_configuration性能架构表中。Issuing RESET REPLICA resets the heartbeat interval to the default value.发出RESET REPLICA将心跳间隔重置为默认值。

The slave_net_timeout system variable specifies the number of seconds that the replica waits for either more data or a heartbeat signal from the source, before the replica considers the connection broken, aborts the read, and tries to reconnect. slave_net_timeout系统变量指定在副本认为连接已断开、中止读取并尝试重新连接之前,副本等待更多数据或来自源的心跳信号的秒数。The default value is 60 seconds (one minute). 默认值为60秒(一分钟)。Note that a change to the value or default setting of slave_net_timeout does not automatically change the heartbeat interval, whether that has been set explicitly or is using a previously calculated default. 请注意,对slave_net_timeout的值或默认设置的更改不会自动更改心跳间隔,无论是显式设置还是使用先前计算的默认值。A warning is issued if you set @@GLOBAL.slave_net_timeout to a value less than that of the current heartbeat interval. 如果将@GLOBAL.slave_net_timeout设置为小于当前心跳间隔的值,则会发出警告。If slave_net_timeout is changed, you must also issue CHANGE REPLICATION SOURCE TO to adjust the heartbeat interval to an appropriate value so that the heartbeat signal occurs before the connection timeout. 如果更改了slave_net_timeout,还必须发出CHANGE REPLICATION SOURCE TO以将心跳间隔调整为适当的值,以便心跳信号在连接超时之前出现。If you do not do this, the heartbeat signal has no effect, and if no data is received from the source, the replica can make repeated reconnection attempts, creating zombie dump threads.如果不这样做,心跳信号将无效,并且如果没有从源接收到任何数据,复制副本可以重复尝试重新连接,从而创建僵尸转储线程。

SOURCE_HOST

The host name or IP address of the replication source server. 复制源服务器的主机名或IP地址。The replica uses this to connect to the source.复制副本使用此连接到源。

If you specify SOURCE_HOST or SOURCE_PORT, the replica assumes that the source server is different from before (even if the option value is the same as its current value.) 如果指定SOURCE_HOSTSOURCE_PORT,复制副本将假定源服务器与以前不同(即使选项值与其当前值相同)。In this case, the old values for the source's binary log file name and position are considered no longer applicable, so if you do not specify SOURCE_LOG_FILE and SOURCE_LOG_POS in the statement, SOURCE_LOG_FILE='' and SOURCE_LOG_POS=4 are silently appended to it.在这种情况下,源的二进制日志文件名和位置的旧值将被视为不再适用,因此,如果在语句中未指定SOURCE_LOG_FILESOURCE_LOG_POS,则SOURCE_LOG_FILE=''SOURCE_LOG_POS=4将以静默方式追加到它。

Setting SOURCE_HOST='' (that is, setting its value explicitly to an empty string) is not the same as not setting SOURCE_HOST at all. 设置SOURCE_HOST=''(即,将其值显式设置为空字符串)与根本不设置SOURCE_HOST不同。Trying to set SOURCE_HOST to an empty string fails with an error.尝试将SOURCE_HOST设置为空字符串失败,并出现错误。

SOURCE_LOG_FILE, SOURCE_LOG_POS

The binary log file name, and the location in that file, at which the replication I/O thread begins reading from the source's binary log the next time the thread starts. 二进制日志文件名以及该文件中的位置,在下次线程启动时复制I/O线程从该位置开始读取源的二进制日志。Specify these options if you are using binary log file position based replication. 如果使用基于二进制日志文件位置的复制,请指定这些选项。SOURCE_LOG_FILE must include the numeric suffix of a specific binary log file that is available on the source server, for example, SOURCE_LOG_FILE='binlog.000145'. SOURCE_LOG_FILE必须包含源服务器上可用的特定二进制日志文件的数字后缀,例如,SOURCE_LOG_FILE='binlog.000145'SOURCE_LOG_POS is the numeric position for the replica to start reading in that file. SOURCE_LOG_POS是复制副本在该文件中开始读取的数字位置。SOURCE_LOG_POS=4 represents the start of the events in a binary log file.SOURCE_LOG_POS=4表示二进制日志文件中事件的开始。

If you specify either of SOURCE_LOG_FILE or SOURCE_LOG_POS, you cannot specify SOURCE_AUTO_POSITION = 1, which is for GTID-based replication.如果指定SOURCE_LOG_FILESOURCE_LOG_POS,则不能指定SOURCE_AUTO_POSITION = 1,该位置用于基于GTID的复制。

If neither of SOURCE_LOG_FILE or SOURCE_LOG_POS is specified, the replica uses the last coordinates of the replication SQL thread before CHANGE REPLICATION SOURCE TO was issued. 如果未指定SOURCE_LOG_FILESOURCE_LOG_POS,则复制副本将使用在发出CHANGE REPLICATION SOURCE TO之前复制SQL线程的最后一个坐标。This ensures that there is no discontinuity in replication, even if the replication SQL thread was late compared to the replication I/O thread.这确保了复制中没有中断,即使复制SQL线程比复制I/O线程晚。

SOURCE_PASSWORD

The password for the replication user account to use for connecting to the replication source server. 用于连接到复制源服务器的复制用户帐户的密码。If you specify SOURCE_PASSWORD, SOURCE_USER is also required.如果指定SOURCE_PASSWORD,则还需要SOURCE_USER

The password used for a replication user account in a CHANGE REPLICATION SOURCE TO statement is limited to 32 characters in length. CHANGE REPLICATION SOURCE TO语句中,复制用户帐户使用的密码长度限制为32个字符。Trying to use a password of more than 32 characters causes CHANGE REPLICATION SOURCE TO to fail.尝试使用超过32个字符的密码会导致CHANGE REPLICATION SOURCE TO失败。

SOURCE_PORT

The TCP/IP port number that the replica uses to connect to the replication source server.复制副本用于连接到复制源服务器的TCP/IP端口号。

Note注意

Replication cannot use Unix socket files. 复制无法使用Unix套接字文件。You must be able to connect to the replication source server using TCP/IP.您必须能够使用TCP/IP连接到复制源服务器。

If you specify SOURCE_HOST or SOURCE_PORT, the replica assumes that the source server is different from before (even if the option value is the same as its current value.) 如果指定SOURCE_HOSTSOURCE_PORT,复制副本将假定源服务器与以前不同(即使选项值与其当前值相同)。In this case, the old values for the source's binary log file name and position are considered no longer applicable, so if you do not specify SOURCE_LOG_FILE and SOURCE_LOG_POS in the statement, SOURCE_LOG_FILE='' and SOURCE_LOG_POS=4 are silently appended to it.在这种情况下,源的二进制日志文件名和位置的旧值将被视为不再适用,因此,如果在语句中未指定SOURCE_LOG_FILESOURCE_LOG_POS,则SOURCE_LOG_FILE=''SOURCE_LOG_POS=4将以静默方式追加到它。

SOURCE_PUBLIC_KEY_PATH

Enables RSA key pair-based password exchange by providing the path name to a file containing a replica-side copy of the public key required by the source. 通过提供包含源所需公钥的副本端副本的文件的路径名,启用基于RSA密钥对的密码交换。The file must be in PEM format. 该文件必须为PEM格式。This option applies to replicas that authenticate with the sha256_password or caching_sha2_password authentication plugin. 此选项适用于使用sha256_passwordcaching_sha2_password身份验证插件进行身份验证的副本。(For sha256_password, SOURCE_PUBLIC_KEY_PATH can be used only if MySQL was built using OpenSSL.) (对于sha256_password,只有在MySQL是使用OpenSSL构建的情况下,才能使用SOURCE_PUBLIC_KEY_PATH。)If you are using a replication user account that authenticates with the caching_sha2_password plugin (which is the default from MySQL 8.0), and you are not using a secure connection, you must specify either this option or the GET_SOURCE_PUBLIC_KEY=1 option to provide the RSA public key to the replica.如果您使用的复制用户帐户使用caching_sha2_password插件(MySQL 8.0中的默认插件)进行身份验证,并且您没有使用安全连接,则必须指定此选项或GET_SOURCE_PUBLIC_KEY=1选项以向复制副本提供RSA公钥。

SOURCE_RETRY_COUNT

Sets the maximum number of reconnection attempts that the replica makes after the connection to the source times out, as determined by the slave_net_timeout system variable. 设置复制副本在与源的连接超时后进行的最大重新连接尝试次数,由系统变量slave_net_timeout确定。If the replica does need to reconnect, the first retry occurs immediately after the timeout.如果复制副本确实需要重新连接,则第一次重试将在超时后立即进行。

The interval between the attempts is specified by the SOURCE_CONNECT_RETRY option. 尝试之间的间隔由SOURCE_CONNECT_RETRY选项指定。If both the default settings are used, the replica waits 60 seconds between reconnection attempts (SOURCE_CONNECT_RETRY=60), and keeps attempting to reconnect at this rate for 60 days (SOURCE_RETRY_COUNT=86400). 如果使用了这两种默认设置,则复制副本在两次重新连接尝试之间等待60秒(SOURCE_CONNECT_RETRY=60),并在60天内继续尝试以此速率重新连接(SOURCE_RETRY_COUNT=86400)。A setting of 0 for SOURCE_RETRY_COUNT means that there is no limit on the number of reconnection attempts, so the replica keeps trying to reconnect indefinitely.SOURCE_RETRY_COUNT设置为0意味着重新连接尝试次数没有限制,因此复制副本会一直尝试无限期重新连接。

The values for SOURCE_CONNECT_RETRY and SOURCE_RETRY_COUNT are recorded in the source metadata repository and shown in the replication_connection_configuration Performance Schema table. SOURCE_CONNECT_RETRYSOURCE_RETRY_COUNT的值记录在源元数据存储库中,并显示在replication_connection_configuration性能架构表中。SOURCE_RETRY_COUNT supersedes the --master-retry-count server startup option.SOURCE_RETRY_COUNT取代--master-retry-count服务器启动选项。

SOURCE_SSL_xxx, SOURCE_TLS_xxx

Specify how the replica uses encryption and ciphers to secure the replication connection. 指定复制副本如何使用加密和密码来保护复制连接。These options can be changed even on replicas that are compiled without SSL support. 即使在不支持SSL的情况下编译的复制副本上,也可以更改这些选项。They are saved to the source metadata repository, but are ignored if the replica does not have SSL support enabled. 它们会保存到源元数据存储库中,但如果复制副本未启用SSL支持,则会被忽略。The SOURCE_SSL_xxx and SOURCE_TLS_xxx options perform the same functions as the --ssl-xxx and --tls-xxx client options described in Command Options for Encrypted Connections. SOURCE_SSL_xxxSOURCE_TLS_xxx选项执行与加密连接的命令选项中描述的--ssl-xxx--tls-xxx客户端选项相同的功能。The correspondence between the two sets of options, and the use of the SOURCE_SSL_xxx and SOURCE_TLS_xxx options to set up a secure connection, is explained in Section 17.3.1, “Setting Up Replication to Use Encrypted Connections”.第17.3.1节,“设置复制以使用加密连接”中解释了两组选项之间的对应关系,以及使用SOURCE_SSL_xxxSOURCE_TLS_xxx选项来设置安全连接。

SOURCE_USER

The user name for the replication user account to use for connecting to the replication source server.用于连接复制源服务器的复制用户帐户的用户名。

Important重要

To connect to the source using a replication user account that authenticates with the caching_sha2_password plugin, you must either set up a secure connection as described in Section 17.3.1, “Setting Up Replication to Use Encrypted Connections”, or enable the unencrypted connection to support password exchange using an RSA key pair. 要使用通过caching_sha2_password插件进行身份验证的复制用户帐户连接到源,必须按照第17.3.1节,“设置复制以使用加密连接”中的说明设置安全连接,或者启用未加密连接以支持使用RSA密钥对的密码交换。The caching_sha2_password authentication plugin is the default for new users created from MySQL 8.0 (for details, see Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication”). caching_sha2_password身份验证插件是MySQL 8.0创建的新用户的默认插件(有关详细信息,请参阅第6.4.1.2节,“缓存SHA-2可插入身份验证”)。If the user account that you create or use for replication uses this authentication plugin, and you are not using a secure connection, you must enable RSA key pair-based password exchange for a successful connection. 如果您创建或用于复制的用户帐户使用此身份验证插件,并且您没有使用安全连接,则必须启用基于RSA密钥对的密码交换才能成功连接。You can do this using either the SOURCE_PUBLIC_KEY_PATH option or the GET_SOURCE_PUBLIC_KEY=1 option for this statement.您可以使用此语句的SOURCE_PUBLIC_KEY_PATH选项或GET_SOURCE_PUBLIC_KEY=1选项来执行此操作。

It is possible to set an empty user name by specifying SOURCE_USER='', but the replication channel cannot be started with an empty user name. 可以通过指定SOURCE_USER=''来设置空用户名,但复制通道不能用空用户名启动。In releases before MySQL 8.0.21, only set an empty SOURCE_USER user name if you need to clear previously used credentials from the replication metadata repositories for security purposes. 在MySQL 8.0.21之前的版本中,仅当出于安全目的需要从复制元数据存储库中清除以前使用的凭据时,才设置空的SOURCE_USER用户名。Do not use the channel afterwards, due to a bug in these releases that can substitute a default user name if an empty user name is read from the repositories (for example, during an automatic restart of a Group Replication channel). 由于这些版本中存在缺陷,如果从存储库中读取空用户名(例如,在自动重新启动组复制通道期间),则可能会替换默认用户名,因此以后不要使用该通道。From MySQL 8.0.21, it is valid to set an empty SOURCE_USER user name and use the channel afterwards if you always provide user credentials using the START REPLICA statement or START GROUP_REPLICATION statement that starts the replication channel. 从MySQL 8.0.21开始,如果始终使用启动复制通道的START REPLACE语句或START GROUP_REPLICATION语句提供用户凭据,则设置空的SOURCE_USER用户名并在之后使用通道是有效的。This approach means that the replication channel always needs operator intervention to restart, but the user credentials are not recorded in the replication metadata repositories.这种方法意味着复制通道总是需要操作员干预才能重新启动,但用户凭据不会记录在复制元数据存储库中。

The text of a running CHANGE REPLICATION SOURCE TO statement, including values for SOURCE_USER and SOURCE_PASSWORD, can be seen in the output of a concurrent SHOW PROCESSLIST statement. 正在运行的CHANGE REPLICATION SOURCE TO语句的文本,包括SOURCE_USERSOURCE_PASSWORD的值,可以在并发SHOW PROCESSLIST语句的输出中看到。(The complete text of a START REPLICA statement is also visible to SHOW PROCESSLIST.)START REPLICA语句的完整文本也在SHOW PROCESSLIST中可见。)

SOURCE_ZSTD_COMPRESSION_LEVEL

The compression level to use for connections to the replication source server that use the zstd compression algorithm. 用于连接到使用zstd压缩算法的复制源服务器的压缩级别。The permitted levels are from 1 to 22, with larger values indicating increasing levels of compression. 允许的水平从1到22,较大的值表示压缩水平增加。The default zstd compression level is 3. 默认的zstd压缩级别为3。The compression level setting has no effect on connections that do not use zstd compression. 压缩级别设置对不使用zstd压缩的连接没有影响。SOURCE_ZSTD_COMPRESSION_LEVEL is available as of MySQL 8.0.18. SOURCE_ZSTD_COMPRESSION_LEVEL从MySQL 8.0.18开始可用。For more information, see Section 4.2.8, “Connection Compression Control”.有关更多信息,请参阅SOURCE_ZSTD_COMPRESSION_LEVEL第4.2.8节,“连接压缩控制”。

The following table shows the maximum permissible length for the string-valued options.下表显示了字符串值选项的最大允许长度。

Option选项Maximum Length最大长度
SOURCE_HOST255
SOURCE_USER96
SOURCE_PASSWORD32
SOURCE_LOG_FILE511
RELAY_LOG_FILE511
SOURCE_SSL_CA511
SOURCE_SSL_CAPATH511
SOURCE_SSL_CERT511
SOURCE_SSL_CRL511
SOURCE_SSL_CRLPATH511
SOURCE_SSL_KEY511
SOURCE_SSL_CIPHER511
SOURCE_TLS_VERSION511
SOURCE_TLS_CIPHERSUITES4000
SOURCE_PUBLIC_KEY_PATH511
SOURCE_COMPRESSION_ALGORITHMS99
NETWORK_NAMESPACE64