Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql database sync between two databases

Tags:

database

mysql

We are running a Java PoS (Point of Sale) application at various shops, with a MySql backend. I want to keep the databases in the shops synchronised with a database on a host server.

When some changes happen in a shop, they should get updated on the host server. How do I achieve this?

like image 230
peedee Avatar asked Oct 10 '11 01:10

peedee


People also ask

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.

What is MySQL synchronization?

MySQL synchronization is a process of making two MySQL databases having identical contents. It's a general idea that is realized differently in clustering, replication and other applications. Handy Backup synchronizes MySQL tables via backup and recovery. Free Download. Version 8.4.0, built on June 30, 2022.


2 Answers

Replication is not very hard to create.

Here's some good tutorials:

http://www.ghacks.net/2009/04/09/set-up-mysql-database-replication/

http://dev.mysql.com/doc/refman/5.5/en/replication-howto.html

http://www.lassosoft.com/Beginners-Guide-to-MySQL-Replication

Here some simple rules you will have to keep in mind (there's more of course but that is the main concept):

  1. Setup 1 server (master) for writing data.
  2. Setup 1 or more servers (slaves) for reading data.

This way, you will avoid errors.

For example: If your script insert into the same tables on both master and slave, you will have duplicate primary key conflict.

You can view the "slave" as a "backup" server which hold the same information as the master but cannot add data directly, only follow what the master server instructions.

NOTE: Of course you can read from the master and you can write to the slave but make sure you don't write to the same tables (master to slave and slave to master).

I would recommend to monitor your servers to make sure everything is fine.

Let me know if you need additional help

like image 196
Book Of Zeus Avatar answered Sep 20 '22 21:09

Book Of Zeus


three different approaches:

  1. Classic client/server approach: don't put any database in the shops; simply have the applications access your server. Of course it's better if you set a VPN, but simply wrapping the connection in SSL or ssh is reasonable. Pro: it's the way databases were originally thought. Con: if you have high latency, complex operations could get slow, you might have to use stored procedures to reduce the number of round trips.

  2. replicated master/master: as @Book Of Zeus suggested. Cons: somewhat more complex to setup (especially if you have several shops), breaking in any shop machine could potentially compromise the whole system. Pros: better responsivity as read operations are totally local and write operations are propagated asynchronously.

  3. offline operations + sync step: do all work locally and from time to time (might be once an hour, daily, weekly, whatever) write a summary with all new/modified records from the last sync operation and send to the server. Pros: can work without network, fast, easy to check (if the summary is readable). Cons: you don't have real-time information.

like image 45
Javier Avatar answered Sep 19 '22 21:09

Javier