如何保持 2 个临时数据库同步

发布于 2024-07-08 23:59:52 字数 413 浏览 8 评论 0原文

我的问题很像这个。 然而,我在 MySQL 上,正在寻找我能找到的“技术含量最低”的解决方案。

情况是我有 2 个数据库,它们应该包含相同的数据,但它们主要在无法相互联系时进行更新。 我怀疑有某种集群或主/从设备可以很好地同步它们。 然而,在我的情况下,这是一个重大的矫枉过正,因为这只是一个供我自己使用的临时数据库。

有什么好的方法可以做到这一点?

我当前的方法是在其中一个上建立一个联合表,并经常通过插入/选择将数据通过线路填充到另一个。 尝试处理主键之类的事情会有点复杂。 (insertignore 似乎无法正常工作)

ps 我可以轻松构建一个查询来选择要传输的行。

My question is a lot like this one. However I'm on MySQL and I'm looking for the "lowest tech" solution that I can find.

The situation is that I have 2 databases that should have the same data in them but they are updated primarily when they are not able to contact each other. I suspect that there is some sort of clustering or master/slave thing that would be able to sync them just fine. However in my cases that is major overkill as this is just a scratch DB for my own use.

What is a good way to do this?

My current approach is to have a Federated table on one of them and, every so often, stuff the data over the wire to the other with an insert/select. It get a bit convoluted trying to deal with primary keys and what not. (insert ignore seems to not work correctly)

p.s. I can easily build a query that selects the rows to transfer.

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

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

发布评论

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

评论(2

小嗷兮 2024-07-15 23:59:52

MySQL 的内置复制非常容易设置,即使在大多数时间数据库断开连接时也能正常工作。 我想说配置它比任何自定义解决方案都要简单得多。

请参阅 http://www.howtoforge.com/mysql_database_replication 了解说明,您应该在 10 天内启动并运行-15分钟,你就不用再考虑了。

我能看到的唯一缺点是它是异步的 - 即。 您必须有一位指定的主人来获取所有更改。

MySQL's inbuilt replication is very easy to set up and works well even when the DBs are disconnected most of the time. I'd say configuring this would be much simpler than any custom solution out there.

See http://www.howtoforge.com/mysql_database_replication for instructions, you should be up and running in 10-15 mins and you won't have to think about it again.

The only downside I can see is that it is asynchronous - ie. you must have one designated master that gets all the changes.

赠我空喜 2024-07-15 23:59:52

我当前的解决方案是

  • 在源框上设置一个联合表,以获取目标框上的表
  • 在源框上设置一个视图,选择要更新的行(作为联合表的联接)
  • 设置另一个联合表在获取源框视图的目标框上,在
  • 目标框上发出 INSERT...SELECT...ON DUPLICATE UPDATE 来运行拉取。

我想我可以获取源表并一次性完成所有操作,但根据我所看到的查询日志,我猜测我最终会运行大约 20K 查询或大约 100-300MB数据传输取决于事情的发生方式。 上述设置导致大约 4 个查询,并且传输的数据比实际需要的数据少一点。

My current solution is

  • set up a federated table on the source box that grabs the table on the target box
  • set up a view on the source box that selects the rows to be updated (as a join of the federated table)
  • set up another federated table on the target box that grabs the view on the source box
  • issue an INSERT...SELECT...ON DUPLICATE UPDATE on the target box to run the pull.

I guess I could just grab the source table and do it all in one shot, but based on the query logs I've been seeing, I'm guessing that I'd end up with about 20K queries being run or about 100-300MB of data transfer depending on how things happen. The above setup sold result in about 4 queries and little more data transfered than actually needed to be.

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