START {REPLICA | SLAVE} [thread_types
] [until_option
] [connection_options
] [channel_option
]thread_types
: [thread_type
[,thread_type
] ... ]thread_type
: IO_THREAD | SQL_THREADuntil_option
: UNTIL { {SQL_BEFORE_GTIDS | SQL_AFTER_GTIDS} =gtid_set
| MASTER_LOG_FILE = 'log_name
', MASTER_LOG_POS =log_pos
| SOURCE_LOG_FILE = 'log_name
', SOURCE_LOG_POS =log_pos
| RELAY_LOG_FILE = 'log_name
', RELAY_LOG_POS =log_pos
| SQL_AFTER_MTS_GAPS }connection_options
: [USER='user_name
'] [PASSWORD='user_pass
'] [DEFAULT_AUTH='plugin_name
'] [PLUGIN_DIR='plugin_dir
']channel_option
: FOR CHANNELchannel
gtid_set
:uuid_set
[,uuid_set
] ... | ''uuid_set
:uuid
:interval
[:interval
]...uuid
:hhhhhhhh
-hhhh
-hhhh
-hhhh
-hhhhhhhhhhhh
h
: [0-9,A-F]interval
:n
[-n
] (n
>= 1)
START REPLICA | SLAVE
starts one or both of the replication threads. START REPLICA | SLAVE
启动一个或两个副本线程。From MySQL 8.0.22, use 在MySQL 8.0.22中,请使用START REPLICA
in place of START SLAVE
, which is deprecated from that release. START REPLICA
代替START SLAVE
,该版本不推荐使用START SLAVE
。In releases before MySQL 8.0.22, use 在MySQL 8.0.22之前的版本中,使用START SLAVE
.START SLAVE
。
使用START REPLICA | SLAVE
with no thread_type
options starts both of the replication threads. thread_type
选项START REPLICA | SLAVE
会启动两个副本线程。The replication I/O thread reads events from the source server and stores them in the relay log. 复制I/O线程从源服务器读取事件并将其存储在中继日志中。The replication SQL thread reads events from the relay log and executes them. 复制SQL线程从中继日志中读取事件并执行它们。START REPLICA | SLAVE
requires the REPLICATION_SLAVE_ADMIN
privilege (or the deprecated SUPER
privilege).START REPLICA | SLAVE
需要REPLICATION_SLAVE_ADMIN
权限(或不推荐使用的SUPER
权限)。
If 如果START REPLICA | SLAVE
succeeds in starting the replication threads, it returns without any error. START REPLICA | SLAVE
成功启动副本线程,它将返回,不会出现任何错误。However, even in that case, it might be that the replication threads start and then later stop (for example, because they do not manage to connect to the source or read its binary log, or some other problem). 但是,即使在这种情况下,也可能是复制线程启动,然后停止(例如,因为它们无法连接到源或读取其二进制日志,或者其他一些问题)。START REPLICA | SLAVE
does not warn you about this. START REPLICA | SLAVE
不会就此向您发出警告。You must check the replica's error log for error messages generated by the replication threads, or check that they are running satisfactorily with 您必须检查复制副本的错误日志,查看复制线程生成的错误消息,或者检查它们是否在SHOW REPLICA | SLAVE STATUS
.SHOW REPLICA | SLAVE STATUS
下正常运行。
START REPLICA | SLAVE
causes an implicit commit of an ongoing transaction. START REPLICA | SLAVE
导致正在进行的事务的隐式提交。See Section 13.3.3, “Statements That Cause an Implicit Commit”.请参阅第13.3.3节,“导致隐式提交的语句”。
在发出此语句之前,必须将gtid_next
must be set to AUTOMATIC
before issuing this statement.gtid_next
设置为AUTOMATIC
。
The optional 可选的FOR CHANNEL
clause enables you to name which replication channel the statement applies to. channel
FOR CHANNEL channel
子句使您能够命名该语句应用于哪个复制通道。Providing a 提供FOR CHANNEL
clause applies the channel
START REPLICA | SLAVE
statement to a specific replication channel. FOR CHANNEL channel
子句将START REPLICA | SLAVE
语句应用于特定的复制通道。If no clause is named and no extra channels exist, the statement applies to the default channel. 如果未命名任何子句且不存在额外通道,则该语句将应用于默认通道。If a 如果在使用多个通道时,START REPLICA | SLAVE
statement does not have a channel defined when using multiple channels, this statement starts the specified threads for all channels. START REPLICA | SLAVE
语句没有定义通道,则该语句将为所有通道启动指定的线程。This statement is disallowed for the 此语句不允许用于group_replication_recovery
channel. group_replication_recovery
通道。See Section 17.2.2, “Replication Channels” for more information.有关更多信息,请参阅第17.2.2节,“复制通道”。
You can add 可以向语句中添加IO_THREAD
and SQL_THREAD
options to the statement to name which of the threads to start. IO_THREAD
和SQL_THREAD
选项,以指定要启动的线程。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线程。Specifying the 在启动此通道时指定IO_THREAD
or SQL_THREAD
options when you start this channel has no benefit.IO_THREAD
或SQL_THREAD
选项没有任何好处。
START REPLICA | SLAVE
supports pluggable user-password authentication with the USER
, PASSWORD
, DEFAULT_AUTH
and PLUGIN_DIR
options, as described in the following list:START REPLICA | SLAVE
支持使用USER
、PASSWORD
、DEFAULT_AUTH
和PLUGIN_DIR
选项进行可插拔用户密码身份验证,如下表所述:
USER
: User name. :用户名。Cannot be set to an empty or null string, or left unset if 不能设置为空字符串或空字符串,如果使用PASSWORD
is used.PASSWORD
,则不能设置为未设置。
PASSWORD
: Password.:密码。
DEFAULT_AUTH
: Name of plugin; default is MySQL native authentication.:插件名称;默认为MySQL本机身份验证。
PLUGIN_DIR
: Location of plugin.:插件的位置。
You cannot use the 在指定任何SQL_THREAD
option when specifying any of USER
, PASSWORD
, DEFAULT_AUTH
, or PLUGIN_DIR
, unless the IO_THREAD
option is also provided.USER
、PASSWORD
、DEFAULT_AUTH
或PLUGIN_DIR
时,都不能使用SQL_THREAD
选项,除非还提供了IO_THREAD
选项。
For more information, see Section 6.2.17, “Pluggable Authentication”.有关更多信息,请参阅第6.2.17节,“可插拔身份验证”。
If an insecure connection is used with any these options, the server issues the warning Sending passwords in plain text without SSL/TLS is extremely insecure.如果不安全的连接与这些选项一起使用,服务器会发出警告:在没有SSL/TLS的情况下以纯文本发送密码是非常不安全的。
START REPLICA | SLAVE ... UNTIL
supports two additional options for use with global transaction identifiers (GTIDs) (see Section 17.1.3, “Replication with Global Transaction Identifiers”). START REPLICA | SLAVE ... UNTIL
还支持两个用于全局事务标识符(GTID)的附加选项(请参阅第17.1.3节,“使用全局事务标识符的复制”)。Each of these takes a set of one or more global transaction identifiers 其中每一个都将一组或多个全局事务标识符gtid_set
as an argument (see GTID Sets, for more information).gtid_set
作为参数(有关更多信息,请参阅GTID集)。
When no 当未指定thread_type
is specified, START REPLICA | SLAVE UNTIL SQL_BEFORE_GTIDS
causes the replication SQL thread to process transactions until it has reached the first transaction whose GTID is listed in the gtid_set
. thread_type
时,START REPLICA | SLAVE UNTIL SQL_BEFORE_GTIDS
导致复制SQL线程处理事务,直到到达gtid_set
中列出其GTID的第一个事务。START REPLICA | SLAVE UNTIL SQL_AFTER_GTIDS
causes the replication threads to process all transactions until the last
transaction in the gtid_set
has been processed by both threads. In other words, START REPLICA | SLAVE UNTIL SQL_BEFORE_GTIDS
causes the replication SQL thread to process all transactions occurring before the first GTID in the gtid_set
is reached, and START REPLICA | SLAVE UNTIL SQL_AFTER_GTIDS
causes the replication threads to handle all transactions, including those whose GTIDs are found in gtid_set
, until each has encountered a transaction whose GTID is not part of the set. SQL_BEFORE_GTIDS
and SQL_AFTER_GTIDS
each support the SQL_THREAD
and IO_THREAD
options, although using IO_THREAD
with them currently has no effect.
For example, START REPLICA | SLAVE SQL_THREAD UNTIL SQL_BEFORE_GTIDS = 3E11FA47-71CA-11E1-9E33-C80AA9429562:11-56
causes the replication SQL thread to process all transactions originating from the source whose server_uuid
is 3E11FA47-71CA-11E1-9E33-C80AA9429562
until it encounters the transaction having sequence number 11; it then stops without processing this transaction. In other words, all transactions up to and including the transaction with sequence number 10 are processed. Executing START REPLICA | SLAVE SQL_THREAD UNTIL SQL_AFTER_GTIDS = 3E11FA47-71CA-11E1-9E33-C80AA9429562:11-56
, on the other hand, would cause the replication SQL thread to obtain all transactions just mentioned from the source, including all of the transactions having the sequence numbers 11 through 56, and then to stop without processing any additional transactions; that is, the transaction having sequence number 56 would be the last transaction fetched by the replication SQL thread.
When using a multithreaded replica with 当使用设置了slave_preserve_commit_order=0
set, there is a chance of gaps in the sequence of transactions that have been executed from the relay log in the following cases:slave_preserve_commit_order=0
的多线程复制副本时,在以下情况下,从中继日志执行的事务序列中可能存在间隙:
killing the coordinator thread终止协调线程
after an error occurs in the applier threads在应用程序线程中发生错误后
mysqld shuts down unexpectedly意外关闭
Use the 使用START REPLICA | SLAVE UNTIL SQL_AFTER_MTS_GAPS
statement to cause a multithreaded replica's worker threads to only run until no more gaps are found in the relay log, and then to stop. START REPLICA | SLAVE UNTIL SQL_AFTER_MTS_GAPS
语句使多线程复制副本的工作线程仅运行,直到在中继日志中找不到更多间隙,然后停止。This statement can take an 此语句可以采用SQL_THREAD
option, but the effects of the statement remain unchanged. SQL_THREAD
选项,但语句的效果保持不变。It has no effect on the replication I/O thread (and cannot be used with the 它对复制I/O线程没有影响(并且不能与IO_THREAD
option).IO_THREAD
选项一起使用)。
Issuing 在多线程副本上发出START REPLICA | SLAVE
on a multithreaded replica with gaps in the sequence of transactions executed from the relay log generates a warning. START REPLICA | SLAVE
,并在中继日志中执行的事务序列中出现间隙,会生成警告。In such a situation, the solution is to use 在这种情况下,解决方案是使用START REPLICA | SLAVE UNTIL SQL_AFTER_MTS_GAPS
, then issue RESET REPLICA | SLAVE
to remove any remaining relay logs. >START REPLICA | SLAVE UNTIL SQL_AFTER_MTS_GAPS
,然后发出RESET REPLICA | SLAVE
,以删除任何剩余的中继日志。See Section 17.5.1.34, “Replication and Transaction Inconsistencies” for more information.有关更多信息,请参阅第17.5.1.34节,“复制和事务不一致”。
To change a failed multithreaded replica to single-threaded mode, you can issue the following series of statements, in the order shown:要将失败的多线程复制副本更改为单线程模式,可以按所示顺序发出以下一系列语句:
START {REPLICA | SLAVE} UNTIL SQL_AFTER_MTS_GAPS; SET @@GLOBAL.slave_parallel_workers = 0; START {REPLICA | SLAVE} SQL_THREAD;
It is possible to view the entire text of a running START REPLICA | SLAVE
statement, including any USER
or PASSWORD
values used, in the output of SHOW PROCESSLIST
. This is also true for the text of a running CHANGE REPLICATION SOURCE TO
| CHANGE MASTER TO
statement, including any values it employs for SOURCE_USER
| MASTER_USER
or SOURCE_PASSWORD
| MASTER_PASSWORD
.
START REPLICA | SLAVE
sends an acknowledgment to the user after both the replication I/O thread and the replication SQL thread have started. However, the replication I/O thread may not yet have connected. 但是,复制I/O线程可能尚未连接。For this reason, a successful START REPLICA | SLAVE
causes SHOW REPLICA | SLAVE STATUS
to show Replica_SQL_Running=Yes
, but this does not guarantee that Replica_IO_Running=Yes
(because Replica_IO_Running=Yes
only if the I/O thread is running and connected). For more information, see Section 13.7.7.35, “SHOW REPLICA | SLAVE STATUS Statement”, and Section 17.1.7.1, “Checking Replication Status”.有关更多信息,请参阅第13.7.7.35节,“SHOW REPLICA | SLAVE STATUS语句”和第17.1.7.1节,“检查复制状态”。
An 可以添加一个UNTIL
clause (until_option
, in the preceding grammar) may be added to specify that the replica should start and run until the replication SQL thread reaches a given point in the source's binary log or in the replica's relay log. UNTIL
子句(前面语法中的until_option
),以指定复制副本应启动并运行,直到复制SQL线程到达源二进制日志或复制副本中继日志中的给定点。Use one of the following pairs of options to specify the position:使用以下选项对之一指定位置:
二进制日志的MASTER_LOG_POS
and MASTER_LOG_FILE
for the binary log (to MySQL 8.0.22).MASTER_LOG_POS
和MASTER_LOG_FILE
(到MySQL 8.0.22结束)。
二进制日志的SOURCE_LOG_POS
and SOURCE_LOG_FILE
for the binary log (from MySQL 8.0.23).SOURCE_LOG_POS
和SOURCE_LOG_FILE
(从MySQL 8.0.23开始)。
中继日志的RELAY_LOG_POS
and RELAY_LOG_FILE
for the relay log.RELAY_LOG_POS
和RELAY_LOG_FILE
。
For compressed transaction payloads, the position must be based on the compressed 对于压缩事务有效负载,位置必须基于压缩的Transaction_payload_event
. Transaction_payload_event
。When the SQL thread reaches the point specified, it stops. 当SQL线程到达指定的点时,它将停止。If the 如果在语句中指定了SQL_THREAD
option is specified in the statement, it starts only the SQL thread. SQL_THREAD
选项,则它只启动SQL线程。Otherwise, it starts both replication threads. 否则,它将启动两个复制线程。If the SQL thread is running, the 如果SQL线程正在运行,将忽略UNTIL
clause is ignored and a warning is issued. UNTIL
子句并发出警告。You cannot use an 不能将UNTIL
clause with the IO_THREAD
option.UNTIL
子句与IO_THREAD
选项一起使用。
It is also possible with START REPLICA | SLAVE UNTIL
to specify a stop point relative to a given GTID or set of GTIDs using one of the options SQL_BEFORE_GTIDS
or SQL_AFTER_GTIDS
, as explained previously in this section. When using one of these options, you can specify SQL_THREAD
, IO_THREAD
, both of these, or neither of them. If you specify only SQL_THREAD
, then only the replication SQL thread is affected by the statement; if only IO_THREAD
is used, then only the replication I/O thread is affected. If both 如果同时使用SQL_THREAD
and IO_THREAD
are used, or if neither of them is used, then both the SQL and I/O threads are affected by the statement.SQL_THREAD
和IO_THREAD
,或者两者均未使用,则SQL和I/O线程都会受到该语句的影响。
For an 对于UNTIL子句,必须指定以下任一项:UNTIL
clause, you must specify any one of the following:
Both a log file name and a position in that file日志文件名和该文件中的位置
Either of SQL_BEFORE_GTIDS
or SQL_AFTER_GTIDS
SQL_BEFORE_GTIDS
或SQL_AFTER_GTIDS
SQL_AFTER_MTS_GAPS
Do not mix source and relay log options. 不要混合使用源和中继日志选项。Do not mix log file options with GTID options.不要将日志文件选项与GTID选项混合使用。
The 对于多线程复制副本,不支持UNTIL
clause is not supported for multithreaded replicas except when also using SQL_AFTER_MTS_GAPS
. UNTIL
子句,除非同时使用SQL_AFTER_MTS_GAPS
。If UNTIL
is used on a multithreaded replica without SQL_AFTER_MTS_GAPS
, the replica operates in single-threaded (sequential) mode for replication until the point specified by the UNTIL
clause is reached.
Any UNTIL
condition is reset by a subsequent STOP REPLICA | SLAVE
statement, a START REPLICA | SLAVE
statement that includes no UNTIL
clause, or a server restart.
When specifying a log file and position, you can use the IO_THREAD
option with START REPLICA | SLAVE ... UNTIL
even though only the SQL thread is affected by this statement. The IO_THREAD
option is ignored in such cases. The preceding restriction does not apply when using one of the GTID options (SQL_BEFORE_GTIDS
and SQL_AFTER_GTIDS
); the GTID options support both SQL_THREAD
and IO_THREAD
, as explained previously in this section.
The UNTIL
clause can be useful for debugging replication, or to cause replication to proceed until just before the point where you want to avoid having the replica replicate an event. UNTIL
子句可用于调试复制,或使复制继续进行,直到您希望避免复制副本复制事件的时间点之前。For example, if an unwise 例如,如果在源上执行了一条不明智的DROP TABLE
statement was executed on the source, you can use UNTIL
to tell the replica to execute up to that point but no farther. DROP TABLE
语句,则可以使用UNTIL
命令复制副本执行到该点,但不能再执行。To find what the event is, use mysqlbinlog with the source's binary log or the replica's relay log, or by using a 要查找事件是什么,请将mysqlbinlog与源的二进制日志或副本的中继日志一起使用,或者使用SHOW BINLOG EVENTS
statement.SHOW BINLOG EVENTS
语句。
If you are using 如果使用UNTIL
to have the replica process replicated queries in sections, it is recommended that you start the replica with the --skip-slave-start
option, or from MySQL 8.0.24, the skip_slave_start
system variable, to prevent the SQL thread from running when the replica server starts. UNTIL
在部分中复制副本进程查询,建议使用--skip-slave-start
选项(或从MySQL 8.0.24开始,使用skip_slave_start
系统变量)启动副本,以防止副本服务器启动时SQL线程运行。Remove the option or system variable setting after the procedure is complete, so that it is not forgotten in the event of an unexpected server restart.在过程完成后删除选项或系统变量设置,以便在服务器意外重启时不会忘记该设置。
The SHOW REPLICA | SLAVE STATUS
statement includes output fields that display the current values of the UNTIL
condition.SHOW REPLICA | SLAVE STATUS
语句包含输出字段,显示UNTIL
条件的当前值。