GarouDan GarouDan - 5 months ago 59
MySQL Question

How to sync two MySQL tables?

If I have a table (let call it

) on one server of mine, named, for example,
. And I have this same table one another server of mine, named, for example,

My problem is, what is the best way to sync this too tables?

I would like a solution that replace 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?


pt-table-sync can do this:

See also other SO questions and answers mentioning pt-table-sync.