Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sync two MySQL tables?

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?

like image 850
GarouDan Avatar asked Mar 22 '13 18:03

GarouDan


People also ask

How can I sync two tables in different databases?

Specifically, you can create a batch sync node, specify tables in multiple databases as the source tables, and then specify the destination table. After that, you can run the batch sync node to synchronize the data from the source tables to the destination table.

How do you sync two databases in MySQL workbench?

To start the wizard, open a model and select Database and then Synchronize With Any Source from the main menu. The steps are similar to the Synchronize Model wizard, but with additional options to create SQL script files, use SQL script files, or both.


1 Answers

pt-table-sync can do this: http://www.percona.com/doc/percona-toolkit/2.1/pt-table-sync.html

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

like image 143
Bill Karwin Avatar answered Sep 18 '22 15:09

Bill Karwin