How to sync two MySQL tables?

2019-02-05 02:58发布

If I have a table (lets call it orders) on one server of mine, named, for example, local. And I have this same table one another server of mine, named, for example, 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:

/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?

3条回答
做个烂人
2楼-- · 2019-02-05 03:04

Arguably the"best" way is to use MySQL replication, documented here: http://dev.mysql.com/doc/refman/5.5/en/replication.html

查看更多
该账号已被封号
3楼-- · 2019-02-05 03:09
Bombasti
4楼-- · 2019-02-05 03:24

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

I'll try it and maybe later I'll write an example.

查看更多
登录 后发表回答