如何保证MySQL复制SLAVE与复制MASTER完全同步?

发布于 2025-01-04 17:59:15 字数 258 浏览 1 评论 0原文

使用一主一从的简单复制设置,如何确保从站和主站完全同步?

现在是的,它们都从完全相同的映像开始,并且复制正在工作并报告一切正常但是: * 曾经发生过停止复制时出现错误,然后必须停止复制然后再恢复的情况。 * 也许 SLAVE 上意外发生了变化,然后它就不再与 MASTER 相同了。 * 其他可能破坏同步的情况。

虽然可以对两个数据库进行大型 mysqldump 并比较文件,但我对一种可以更轻松实现并且可以自动检查以确保所有内容同步的方法感兴趣。

谢谢

Using simple replication settings with one MASTER and one SLAVE, how can one ensure that the SLAVE and MASTER are fully synchronized?

Now yes, they both started from the exact same image and replication is working and reporting that everything is okay BUT:
* It has happened that there were errors stopping the replication and then the replication had to be stopped and later resumed.
* Perhaps a change accidentally occurred on the SLAVE and then it's not the same as the MASTER anymore.
* Other whichever scenarios that might break sync.

While it's possible to do a big mysqldump of both database and compare the files I would be interested in a method that can be implemented more easily and also can be checked automatically to ensure all is in sync.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤蝉 2025-01-11 17:59:15

您尝试过 Percona Toolkit(以前称为 Maatkit)吗?您可以使用他们的工具之一,即 pt-table-checksum对于你的情况。您也可以在他们的网站上查看其他工具。

pt-table-checksum 通过以下方式执行在线复制一致性检查
在主机上执行校验和查询,这会产生不同的
副本上的结果与主副本不一致。这
可选 DSN 指定主控主机。该工具的退出状态是
如果发现任何差异,或者如果有任何警告或错误,则非零
发生。

以下命令将连接到复制主机
本地主机,对每个表进行校验和,并报告每个表的结果
检测到的副本:

Have you tried Percona Toolkit (formerly known as Maatkit)? You can use one of their tools which is pt-table-checksum for your case. You can check other tools too at their website.

pt-table-checksum performs an online replication consistency check by
executing checksum queries on the master, which produces different
results on replicas that are inconsistent with the master. The
optional DSN specifies the master host. The tool’s exit status is
nonzero if any differences are found, or if any warnings or errors
occur.

The following command will connect to the replication master on
localhost, checksum every table, and report the results on every
detected replica:

桃扇骨 2025-01-11 17:59:15

如果您拥有 MySQL Server 版本 5.6.14 或更高版本,则可以使用 MySQL 复制同步检查器。它包含在 MySql 服务器包中。专门设计用于支持全局事务标识符 (GTID) 且 gtid_mode=ON 的服务器。

此实用程序允许您检查复制服务器的同步情况。它检查主设备和从设备之间或两个从设备之间的数据一致性。该实用程序报告丢失的对象以及丢失的数据。
该实用程序可以在活动复制拓扑上运行,应用同步过程来检查数据。仍然可以检查那些复制未激活的服务器,但同步过程将被跳过。在这种情况下,由用户手动同步服务器。

有关详细信息,请参阅 MySQL 文档

If you have MySQL Server versions 5.6.14 or higher, you can use the MySQL Replication Synchronization Checker. It's included in the MySql server package. Is designed to work exclusively for servers that support global transaction identifiers (GTIDs) and have gtid_mode=ON.

This utility permits you to check replication servers for synchronization. It checks data consistency between a master and slaves or between two slaves. The utility reports missing objects as well as missing data.
The utility can operate on an active replication topology, applying a synchronization process to check the data. Those servers where replication is not active can still be checked but the synchronization process will be skipped. In that case, it is up to the user to manually synchronize the servers.

See MySQL Documentation for more information

江挽川 2025-01-11 17:59:15

您对看似健康的主/从复制设置的怀疑是正确的!当我们突然收到来自 check_mk 的警报时,我们运行得很好,该警报涉及我们的主服务器上存在的数据库,而我们的从服务器上不存在......但是主服务器和从服务器的状态输出都很好!这有多令人不安?证明过程完整性的方法是使用校验和来验证数据。

我在互联网上看到很多推荐 pt-table-checksum 。然而,它的局限性被证明是太繁重了,让我们感到不舒服。最重要的是,它需要甚至设置基于语句的复制(请参阅 pt-table-checksum 链接)。正如mysql 5.6在线文档中所述,(对于基于行的复制...)“所有更改都可以复制。这是最安全的复制形式。”基于语句的复制还有其他缺点,让我们的开发人员感到紧张,因为某些功能无法正确复制;请参阅文档以获取列表。

我们已经遇到过使用基于语句的复制的主服务器和从服务器的问题,因此我们特别努力避免它。

我们将尝试 mysqlrplsync,它特别提到它 " 独立工作二进制日志格式(行、语句或混合)”。然而,它还提到必须打开 gtid-mode,并且它需要 MySQL 5.6.14 及更高版本...我相信,这意味着 RHEL7/CentOS 7 附带的 MySQL 至少已经过时了。您需要获取 MySQL Community Edition,该版本留给读者作为练习但是您可以此处获取软件包此处获取存储库,包括 RHEL 衍生品和 Debian

You are right to be suspicious of a seemingly healthy master/slave replication setup! We were running fine when suddenly we got alerts from check_mk concerning a database that existed on our master that did not exist on our slave... but the master and slave status outputs were good! How unnerving is that? The way to prove integrity of the process is to use checksums to verify the data.

I have seen a lot of chatter on the Internet recommending pt-table-checksum . However, its limitations proved to be too onerous for us to be comfortable with. Most importantly, it requires and even sets statement-based replication (see the pt-table-checksum link). As it says in the mysql 5.6 online documentation, (for row-based replication...) "all changes can be replicated. This is the safest form of replication." There are other disadvantages to statement-based replication that make our developers nervous because some functions cannot be replicated properly; see the doc for a list.

We have already experienced issues with a master and slave using statement-based replication so we're specifically trying to avoid it.

We are going to try mysqlrplsync which specifically mentions that it "works independently of the binary log format (row, statement, or mixed)". It also mentions, however, that gtid-mode must be on and it requires MySQL 5.6.14 and higher... which means, I believe, that the MySQL delivered with RHEL7/CentOS 7 at least is out. You'll need to get the MySQL Community Edition, which is left as an exercise for the reader but you can go here for the packages or here for the repos, including RHEL derivatives and Debian.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文