- 19.1.6.1 复制和二进制日志选项及变量参考19.1.6.1 Replication and Binary Logging Option and Variable Reference
- 19.1.6.2 复制源选项及变量19.1.6.2 Replication Source Options and Variables
- 19.1.6.3 从服务器选项及变量19.1.6.3 Replica Server Options and Variables
- 19.1.6.4 二进制日志选项及变量19.1.6.4 Binary Logging Options and Variables
- 19.1.6.5 全局事务 ID 系统变量19.1.6.5 Global Transaction ID System Variables
以下各节包含有关mysqld选项和服务器变量的信息,这些选项和变量用于复制和控制二进制日志。用于源和副本的选项和变量分别介绍,与二进制日志和全局事务标识符(GTID)相关的选项和变量也分别介绍。还包括一组提供这些选项和变量基本信息的快速参考表。The following sections contain information about mysqld options and server variables that are used in replication and for controlling the binary log. Options and variables for use on sources and replicas are covered separately, as are options and variables relating to binary logging and global transaction identifiers (GTIDs). A set of quick-reference tables providing basic information about these options and variables is also included.
特别重要的是server_id系统变量。
Of particular importance is the
server_id system variable.
| 命令行格式Command-Line Format | --server-id=# |
|---|---|
| 系统变量System Variable | server_id |
| 范围Scope | 全球Global |
| 动态Dynamic | 是Yes |
SET_VAR 提示适用SET_VAR Hint Applies |
否No |
| 类型Type | 整数Integer |
| 默认值Default Value | 1 |
| 最小值Minimum Value | 0 |
| 最大值Maximum Value | 4294967295 |
此变量指定服务器 ID。server_id 默认设置为 1。服务器可以使用此默认 ID 启动,但当启用二进制日志记录时,如果您没有明确设置 server_id 来指定服务器 ID,将会发出一条信息性消息。This variable specifies the server ID.
server_id is set to 1 by default.
The server can be started with this default ID, but when binary
logging is enabled, an informational message is issued if you did
not set server_id explicitly to
specify a server ID.
对于用于复制拓扑的服务器,必须为每个复制服务器指定唯一的服务器 ID,范围从 1 到 232 − 1。“唯一” 意味着每个 ID 必须与复制拓扑中任何其他源或副本使用的 ID 不同。如需更多信息,请参阅 第 19.1.6.2 节,“复制源选项与变量”,以及 第 19.1.6.3 节,“副本服务器选项与变量”。For servers that are used in a replication topology, you must specify a unique server ID for each replication server, in the range from 1 to 232 − 1. “Unique” means that each ID must be different from every other ID in use by any other source or replica in the replication topology. For additional information, see Section 19.1.6.2, “Replication Source Options and Variables”, and Section 19.1.6.3, “Replica Server Options and Variables”.
如果服务器 ID 设置为 0,则会进行二进制日志记录,但服务器 ID 为 0 的源会拒绝来自副本的任何连接,而服务器 ID 为 0 的副本会拒绝连接到源。请注意,虽然可以将服务器 ID 动态更改为非零值,但这样做并不会立即启用复制。必须先更改服务器 ID,然后重启服务器以初始化副本。If the server ID is set to 0, binary logging takes place, but a source with a server ID of 0 refuses any connections from replicas, and a replica with a server ID of 0 refuses to connect to a source. Note that although you can change the server ID dynamically to a nonzero value, doing so does not enable replication to start immediately. You must change the server ID and then restart the server to initialize the replica.
有关更多信息,请参见 第 19.1.2.2 节,“设置副本配置”。For more information, see Section 19.1.2.2, “Setting the Replica Configuration”.
MySQL 服务器除了在 server_id 系统变量中设置的默认或用户提供的服务器 ID 外,还会生成一个真实的 UUID。这个 UUID 可作为全局的只读变量 server_uuid 使用。The MySQL server generates a true UUID in addition to the default or
user-supplied server ID set in the server_id
system variable. This is available as the global, read-only variable
server_uuid.
server_uuid 系统变量的存在并不会改变在准备和运行 MySQL 复制时为每个 MySQL 服务器设置唯一 server_id 值的要求,如本节前面所述。The presence of the server_uuid
system variable does not change the requirement for setting a
unique server_id value for each
MySQL server as part of preparing and running MySQL replication,
as described earlier in this section.
| 系统变量System Variable | server_uuid |
|---|---|
| 范围Scope | 全球Global |
| 动态Dynamic | 否No |
SET_VAR 提示适用SET_VAR Hint Applies |
否No |
| 类型Type | 字符串String |
启动时,MySQL 服务器会自动获取 UUID,具体如下:When starting, the MySQL server automatically obtains a UUID as follows:
尝试读取并使用写入文件
中的 UUID(其中data_dir/auto.cnfdata_dir是服务器的数据目录)。 Attempt to read and use the UUID written in the file(wheredata_dir/auto.cnfdata_diris the server's data directory).如果未找到
,则生成一个新的 UUID 并将其保存到该文件中,如有必要则创建该文件。Ifdata_dir/auto.cnfis not found, generate a new UUID and save it to this file, creating the file if necessary.data_dir/auto.cnf
auto.cnf 文件的格式类似于 my.cnf 或 my.ini 文件的格式。auto.cnf 只有一个 [auto] 部分,包含一个 server_uuid 设置及其值;文件内容类似如下所示:The auto.cnf file has a format similar to that
used for my.cnf or my.ini
files. auto.cnf has only a single
[auto] section containing a single
server_uuid setting and value; the
file's contents appear similar to what is shown here:
[auto] server_uuid=8a94f357-aab4-11df-86ab-c80aa9429562
auto.cnf 文件是自动生成的;请不要试图编写或修改此文件。The auto.cnf file is automatically generated;
do not attempt to write or modify this file.
在使用 MySQL 复制时,源和副本会知道彼此的 UUID。可以在 SHOW REPLICAS 的输出中查看副本的 UUID 值。一旦执行了 START REPLICA,源的 UUID 值就可以在副本的 SHOW REPLICA STATUS 输出中查看。When using MySQL replication, sources and replicas know each
other's UUIDs. The value of a replica's UUID can be seen
in the output of SHOW REPLICAS. Once
START REPLICA has been executed, the
value of the source's UUID is available on the replica in the
output of SHOW REPLICA STATUS.
发出 STOP REPLICA 或 RESET REPLICA 语句 不会 重置副本上使用的源的 UUID。Issuing a STOP REPLICA or
RESET REPLICA statement does
not reset the source's UUID as used on
the replica.
服务器的 server_uuid 也用于该服务器上发起事务的 GTID。有关更多信息,请参见 第 19.1.3 节,“使用全局事务标识符的复制”。A server's server_uuid is also used in GTIDs
for transactions originating on that server. For more information,
see Section 19.1.3, “Replication with Global Transaction Identifiers”.
在启动时,如果源的 UUID 与自身相同,复制 I/O(接收器)线程会生成错误并中止,除非已设置 --replicate-same-server-id 选项。此外,如果满足以下任一条件,复制接收线程会生成警告:When starting, the replication I/O (receiver) thread generates an
error and aborts if its source's UUID is equal to its own
unless the --replicate-same-server-id
option has been set. In addition, the replication receiver thread
generates a warning if either of the following is true:
不存在具有预期
server_uuid的源。No source having the expectedserver_uuidexists.源的
server_uuid已更改,尽管从未执行过CHANGE REPLICATION SOURCE TO语句。The source'sserver_uuidhas changed, although noCHANGE REPLICATION SOURCE TOstatement has ever been executed.