mysql 复制 - 主从

发布于 2024-12-03 05:42:24 字数 459 浏览 1 评论 0原文

我已经成功设置了主从环境,并且它绝对工作正常。

我遇到的唯一问题是从表中选择计数,它们不一样,但是在从主服务器上选择 5 分钟后,在从服务器上创建了 50 行,也创建了 50 行(这就是为什么我说我确信工作正常)

主人:

+----------+
| COUNT(*) |
+----------+
|    77634 |
+----------+
1 row in set (0.00 sec)

奴隶:

+----------+
| COUNT(*) |
+----------+
|    76932 |
+----------+
1 row in set (0.00 sec)

知道为什么会发生这种情况吗?当我使用“CHANGE MASTER TO”命令将从站更改为指向主站时,是否有可能,二进制日志文件@主站的位置已经移动了?

I have successfully set up a master to slave environment and it is definitely working fine.

The only problem I have is that selecting count from a table, they are not the same BUT selecting after 5 mins from master, 50 rows are created while on the slave, also 50 rows are created (that's why I said i'm sure that is working fine)

Master:

+----------+
| COUNT(*) |
+----------+
|    77634 |
+----------+
1 row in set (0.00 sec)

Slave:

+----------+
| COUNT(*) |
+----------+
|    76932 |
+----------+
1 row in set (0.00 sec)

Any idea why this happened? is it possible that when I changed the slave to point to the master using the 'CHANGE MASTER TO' command, the position of binary log file @ the Master moved already?

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

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

发布评论

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

评论(2

并安 2024-12-10 05:42:24

在从站上尝试“显示从站状态”以查看是否发生任何错误。

您还可以尝试从主服务器加载数据以重新建立同步。

Try 'SHOW SLAVE STATUS' on the slave to see if any errors have occured.

You can also try load data from master in order to re-establish the synchronization.

夏尔 2024-12-10 05:42:24

MySQL 复制并不“可靠”,如果出现问题也无法自动重新同步。即使没有计划外的重新启动等,它也有很多可能会出错的方式。

您需要积极监控它,以保证它在任何时间内都能正常工作。

您至少需要做两件事:

  1. 检查SHOW SLAVE STATUS(在每个从属设备上)的输出,以确保线程正在运行,没有报告错误,并且秒数_behind_master 不是太多。
  2. 定期对每个从站/主站运行某种一致性检查 - 我建议使用 --replication 选项 mk-table-checksum

并将这些检查的输出挂接到您的监控系统,以便您的操作人员收到警报。

您的运维人员还需要知道如何修复它(转储/恢复,或其他一些修复)。您肯定需要为运维编写某种知识库文章。

我以前这样做过——这并不是一件小事,你很容易出错。

MySQL replication is not "reliable", nor is it able to automatically re-sync if it goes wrong. There are lots of ways it can go wrong even without unplanned reboots etc.

You need to ACTIVELY monitor it, to stand any chance of it working for any length of time.

You need, at the very least, to do two things:

  1. Check the output of SHOW SLAVE STATUS (on each slave) to ensure that the threads are running, no errors reported and seconds_behind_master is not too much.
  2. Periodically run some kind of consistency check on each slave / master - I recommend mk-table-checksum with the --replication option

And hook the output of those checks up to your monitoring system so that your operations staff get alerted.

Your Ops staff also need to know how to fix it (dump / restore, or some other fix). You will definitely need to write some kind of knowledge-base article for Ops.

I did this before - it is not trivial and you can get it wrong easily.

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