[英]How to sync two MySQL tables?
If I have a table (lets call it orders
) on one server of mine, named, for example, local
.如果我在我的一台服务器上有一个表(我们称之为
orders
),例如命名为local
。 And I have this same table one another server of mine, named, for example, remote
.我的另一台服务器也有同一张表,例如名为
remote
。
My problem is, what is the best way to sync these two tables?我的问题是,同步这两个表的最佳方法是什么?
I would like a solution that replaces a registry if the local is different of the remote one.如果本地与远程不同,我想要一个替换注册表的解决方案。 And insert the registry if it doesn't exist on the local table.
如果本地表上不存在注册表,则插入注册表。
I had tried using dump a dump command similar to this one, but didn't worked as expected:我曾尝试使用 dump 类似于此的转储命令,但没有按预期工作:
/usr/bin/mysqldump --defaults-file=~/my/conf.cnf --skip-opt --skip-add-locks --default-character-set=latin1 --disable-keys --no-create-db --no-create-info --dump-date --compress --quick --replace --where='date > DATE_SUB(NOW(), INTERVAL 1 DAY)' mydb orders >> /backup/myDump
How can I do this?我怎样才能做到这一点? How could I do a script to do this?
我怎么能做一个脚本来做到这一点?
pt-table-sync can do this: http://www.percona.com/doc/percona-toolkit/2.1/pt-table-sync.html pt-table-sync可以做到这一点: http : //www.percona.com/doc/percona-toolkit/2.1/pt-table-sync.html
See also other SO questions and answers mentioning pt-table-sync. 另请参阅提及pt-table-sync的其他SO问题和答案 。
可以说“最好”的方法是使用MySQL复制,在此处记录: http : //dev.mysql.com/doc/refman/5.5/en/replication.html
I am solving similar problem of syncing two tables constantly. 我正在解决不断同步两个表的类似问题。
Among all the scripts (of which most are old) I've found this actively developed app (looks promising) 在所有脚本中(其中大多数是旧的)我发现这个积极开发的应用程序(看起来很有前途)
https://github.com/mrjgreen/db-sync https://github.com/mrjgreen/db-sync
I'll try it and maybe later I'll write an example. 我会尝试一下,也许以后我会写一个例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.