RESET MASTER [TO binary_log_file_index_number
]
Use this statement with caution to ensure you do not lose any wanted binary log file data and GTID execution history.请谨慎使用此语句,以确保不会丢失任何需要的二进制日志文件数据和GTID执行历史记录。
RESET MASTER
requires the RELOAD
privilege.RESET MASTER
需要RELOAD
权限。
For a server where binary logging is enabled (对于启用二进制日志记录的服务器(log_bin
is ON
), RESET MASTER
deletes all existing binary log files and resets the binary log index file, resetting the server to its state before binary logging was started. log_bin
处于ON
状态),RESET MASTER
会删除所有现有的二进制日志文件并重置二进制日志索引文件,从而将服务器重置为二进制日志记录启动前的状态。A new empty binary log file is created so that binary logging can be restarted.将创建一个新的空二进制日志文件,以便可以重新启动二进制日志记录。
For a server where GTIDs are in use (对于使用gtid的服务器(gtid_mode
is ON
), issuing RESET MASTER
resets the GTID execution history. gtid_mode
为ON
),发出RESET MASTER
会重置gtid执行历史记录。The value of the gtid_purged
system variable is set to an empty string (''
), the global value (but not the session value) of the gtid_executed
system variable is set to an empty string, and the mysql.gtid_executed
table is cleared (see mysql.gtid_executed Table). gtid_purged
系统变量的值设置为空字符串(''
),gtid_executed
系统变量的全局值(但不是会话值)设置为空字符串,并清除mysql.gtid_executed
表(请参阅mysql.gtid_executed表)。If the GTID-enabled server has binary logging enabled, 如果启用GTID的服务器启用了二进制日志记录,则RESET MASTER
also resets the binary log as described above. RESET MASTER
也会如上所述重置二进制日志。Note that 请注意,RESET MASTER
is the method to reset the GTID execution history even if the GTID-enabled server is a replica where binary logging is disabled; RESET REPLICA | SLAVE
has no effect on the GTID execution history. RESET MASTER
是重置GTID执行历史记录的方法,即使启用GTID的服务器是禁用二进制日志记录的副本;RESET REPLICA | SLAVE
对GTID执行历史没有影响。For more information on resetting the GTID execution history, see Resetting the GTID Execution History.有关重置GTID执行历史记录的更多信息,请参阅重置GTID执行历史记录。
Issuing 在没有可选的RESET MASTER
without the optional TO
clause deletes all binary log files listed in the index file, resets the binary log index file to be empty, and creates a new binary log file starting at 1
. TO
子句的情况下发出RESET MASTER
将删除索引文件中列出的所有二进制日志文件,将二进制日志索引文件重置为空,并从1
开始创建一个新的二进制日志文件。Use the optional 重置后,使用可选的TO
clause to start the binary log file index from a number other than 1
after the reset.TO
子句从1
以外的数字开始二进制日志文件索引。
Using 使用RESET MASTER
with the TO
clause to specify a binary log file index number to start from simplifies failover by providing a single statement alternative to the FLUSH BINARY LOGS
and PURGE BINARY LOGS TO
statements. RESET MASTER
配合TO
子句指定要从中开始的二进制日志文件索引号,通过提供一条替换语句替代FLUSH BINARY LOGS
语句和PURGE BINARY LOGS TO
语句,简化了故障切换。Check that you are using a reasonable value for the index number. 检查索引号是否使用了合理的值。If you enter an incorrect value, you can correct this by issuing another 如果输入的值不正确,可以通过发出另一条带或不带RESET MASTER
statement with or without the TO
clause. TO
子句的RESET MASTER
语句来更正此错误。If you do not correct a value that is out of range, the server cannot be restarted.如果不更正超出范围的值,则无法重新启动服务器。
The following example demonstrates 以下示例演示TO
clause usage:TO
子句的用法:
RESET MASTER TO 1234; SHOW BINARY LOGS; +-------------------+-----------+-----------+ | Log_name | File_size | Encrypted | +-------------------+-----------+-----------+ | source-bin.001234 | 154 | No | +-------------------+-----------+-----------+
The effects of 不带RESET MASTER
without the TO
clause differ from those of PURGE BINARY LOGS
in 2 key ways:TO
子句的RESET MASTER
的效果与PURGE BINARY LOGS
的效果在两个关键方面不同:
RESET MASTER
removes all binary log files that are listed in the index file, leaving only a single, empty binary log file with a numeric suffix of .000001
, whereas the numbering is not reset by PURGE BINARY LOGS
.RESET MASTER
删除索引文件中列出的所有二进制日志文件,只留下一个数字后缀为.000001
的空二进制日志文件,而PURGE BINARY LOGS
不会重置编号。
在运行任何复制副本时,不打算使用RESET MASTER
is not intended to be used while any replicas are running. RESET MASTER
。The behavior of 在副本运行时使用RESET MASTER
when used while replicas are running is undefined (and thus unsupported), whereas PURGE BINARY LOGS
may be safely used while replicas are running.RESET MASTER
的行为未定义(因此不受支持),而在副本运行时可以安全地使用PURGE BINARY LOGS
。
See also Section 13.4.1.1, “PURGE BINARY LOGS Statement”.另请参阅第13.4.1.1节,“清除二进制日志语句”。
在首次设置源和复制副本时,如果不使用RESET MASTER
without the TO
clause can prove useful when you first set up a source and replica, so that you can verify the setup as follows:TO
子句,则可以使用RESET MASTER
,以便按如下方式验证设置:
Start the source and replica, and start replication (see Section 17.1.2, “Setting Up Binary Log File Position Based Replication”).启动源和副本,并启动复制(请参阅第17.1.2节,“设置二进制日志文件基于位置的复制”)。
Execute a few test queries on the source.对源代码执行一些测试查询。
Check that the queries were replicated to the replica.检查查询是否已复制到副本。
When replication is running correctly, issue 复制正确运行时,在复制副本上发出STOP REPLICA | SLAVE
followed by RESET REPLICA | SLAVE
on the replica, then verify that no unwanted data from the test queries exists on the replica.STOP REPLICA | SLAVE
,然后RESET REPLICA | SLAVE
,然后验证复制副本上不存在来自测试查询的不需要的数据。
Issue 在源上发出RESET MASTER
on the source to clean up the test queries.RESET MASTER
以清除测试查询。
After verifying the setup, resetting the source and replica and ensuring that no unwanted data or binary log files generated by testing remain on the source or replica, you can start the replica and begin replicating.在验证设置、重置源和副本并确保源或副本上没有保留测试生成的不需要的数据或二进制日志文件后,您可以启动副本并开始复制。