如何保持 2 个临时数据库同步
我的问题很像这个。 然而,我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
我当前的解决方案是
INSERT...SELECT...ON DUPLICATE UPDATE
来运行拉取。我想我可以获取源表并一次性完成所有操作,但根据我所看到的查询日志,我猜测我最终会运行大约 20K 查询或大约 100-300MB数据传输取决于事情的发生方式。 上述设置导致大约 4 个查询,并且传输的数据比实际需要的数据少一点。
My current solution is
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.