8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

19.5.4 复制故障排除19.5.4 Troubleshooting Replication

如果您已按照说明操作但复制设置仍无法正常工作,首先要做的是 检查错误日志以获取信息。许多用户在遇到问题后未能尽早检查错误日志,从而浪费了时间。If you have followed the instructions but your replication setup is not working, the first thing to do is check the error log for messages. Many users have lost time by not doing this soon enough after encountering problems.

如果无法从错误日志中判断问题所在,请尝试以下方法:If you cannot tell from the error log what the problem was, try the following techniques:

  • 通过执行SHOW BINARY LOG STATUS语句来验证源是否启用了二进制日志。二进制日志默认是启用的。如果二进制日志启用,则Position不为零。如果未启用二进制日志,请确认您没有使用任何禁用二进制日志的设置运行源,例如--skip-log-bin选项。Verify that the source has binary logging enabled by issuing a SHOW BINARY LOG STATUS statement. Binary logging is enabled by default. If binary logging is enabled, Position is nonzero. If binary logging is not enabled, verify that you are not running the source with any settings that disable binary logging, such as the --skip-log-bin option.

  • 验证在源和副本上启动时server_id系统变量是否已设置,并且每个服务器的 ID 值是否唯一。Verify that the server_id system variable was set at startup on both the source and replica and that the ID value is unique on each server.

  • 验证副本是否正在运行。使用 SHOW REPLICA STATUS 检查 Replica_IO_Running 和 Replica_SQL_Running 的值是否都为 Yes。如果不是,请验证启动副本服务器时使用的选项。例如,--skip-replica-start 会阻止复制线程启动,直到您发出 START REPLICA 语句。Verify that the replica is running. Use SHOW REPLICA STATUS to check whether the Replica_IO_Running and Replica_SQL_Running values are both Yes. If not, verify the options that were used when starting the replica server. For example, --skip-replica-start prevents the replication threads from starting until you issue a START REPLICA statement.

  • 如果复制正在运行,检查它是否已建立与源的连接。使用 SHOW PROCESSLIST,找到 I/O(接收器)线程和 SQL(应用器)线程,并检查它们的 State 列以查看显示内容。参见 第 19.2.3 节,“复制线程”。如果接收器线程状态显示 Connecting to master,请检查以下内容:If the replica is running, check whether it established a connection to the source. Use SHOW PROCESSLIST, find the I/O (receiver) and SQL (applier) threads and check their State column to see what they display. See Section 19.2.3, “Replication Threads”. If the receiver thread state says Connecting to master, check the following:

    • 验证源上的复制用户权限。Verify the privileges for the replication user on the source.

    • 检查源的主机名是否正确,并确保您使用的是正确的端口连接到源。用于复制的端口与客户端网络通信使用的端口相同(默认是3306)。对于主机名,请确保该名称解析到正确的 IP 地址。Check that the host name of the source is correct and that you are using the correct port to connect to the source. The port used for replication is the same as used for client network communication (the default is 3306). For the host name, ensure that the name resolves to the correct IP address.

    • 检查配置文件,查看是否在源或副本上启用了skip_networking系统变量以禁用网络。如果是,请注释该设置或将其删除。Check the configuration file to see whether the skip_networking system variable has been enabled on the source or replica to disable networking. If so, comment the setting or remove it.

    • 如果源配置了防火墙或 IP 过滤,请确保用于 MySQL 的网络端口未被过滤。If the source has a firewall or IP filtering configuration, ensure that the network port being used for MySQL is not being filtered.

    • 检查是否可以通过使用ping或traceroute/tracert到达该主机。Check that you can reach the source by using ping or traceroute/tracert to reach the host.

  • 如果副本之前运行正常但现在已停止,通常原因是某些在源上成功的语句在副本上失败。如果你已对源进行了适当的快照,并且从未在副本上修改过复制线程以外的数据,这种情况永远不应该发生。如果副本意外停止,这是一个错误,或者你遇到了在第 19.5.1 节,“复制功能和问题”中描述的已知复制限制之一。如果这是一个错误,请参阅第 19.5.5 节,“如何报告复制错误或问题”,了解如何报告它的说明。If the replica was running previously but has stopped, the reason usually is that some statement that succeeded on the source failed on the replica. This should never happen if you have taken a proper snapshot of the source, and never modified the data on the replica outside of the replication threads. If the replica stops unexpectedly, it is a bug or you have encountered one of the known replication limitations described in Section 19.5.1, “Replication Features and Issues”. If it is a bug, see Section 19.5.5, “How to Report Replication Bugs or Problems”, for instructions on how to report it.

  • 如果在源端执行成功的语句在副本上无法运行,当无法通过删除副本数据库并从源端复制新的快照来进行完整数据库重新同步时,请尝试以下步骤:If a statement that succeeded on the source refuses to run on the replica, try the following procedure if it is not feasible to do a full database resynchronization by deleting the replica's databases and copying a new snapshot from the source:

    1. 确定副本上受影响的表是否与源表不同。尝试了解这是如何发生的。然后使副本表与源表相同,并运行 START REPLICA。Determine whether the affected table on the replica is different from the source table. Try to understand how this happened. Then make the replica's table identical to the source's and run START REPLICA.

    2. 如果前一步不起作用或不适用,尝试了解是否可以安全地手动执行更新(如有必要),然后忽略源端的下一条语句。If the preceding step does not work or does not apply, try to understand whether it would be safe to make the update manually (if needed) and then ignore the next statement from the source.

    3. 如果你决定副本可以跳过源端的下一条语句,请执行以下语句:If you decide that the replica can skip the next statement from the source, issue the following statements:

      mysql> SET GLOBAL sql_replica_skip_counter = N;
      mysql> START REPLICA;
      

      如果源中的下一条语句不使用 AUTO_INCREMENT 或 LAST_INSERT_ID(),则 N 的值应为 1。否则,该值应为 2。之所以对使用 AUTO_INCREMENT 或 LAST_INSERT_ID() 的语句使用值 2,是因为它们在源的二进制日志中会产生两个事件。The value of N should be 1 if the next statement from the source does not use AUTO_INCREMENT or LAST_INSERT_ID(). Otherwise, the value should be 2. The reason for using a value of 2 for statements that use AUTO_INCREMENT or LAST_INSERT_ID() is that they take two events in the binary log of the source.

    4. 如果您确信复制一开始与源完全同步,并且没有人在复制线程之外更新所涉及的表,那么差异很可能是由错误引起的。如果您正在运行最新版本的 MySQL,请报告该问题。如果您正在运行旧版本,请尝试升级到最新的生产版本,以确定问题是否仍然存在。If you are sure that the replica started out perfectly synchronized with the source, and that no one has updated the tables involved outside of the replication threads, then presumably the discrepancy is the result of a bug. If you are running the most recent version of MySQL, please report the problem. If you are running an older version, try upgrading to the latest production release to determine whether the problem persists.