ilyo
ilyo

Reputation: 36411

Synchronizing mySQL database between 2 computers

I am using sugarsync to sync the localhost folders between a mac and a PC,
I want to sync the the database also.
Can I do it by simply synchronizing folders (I use xampp on the PC and WAMP on the mac) or is it more complicated then that? and if it is possible what files and folder I should synchronize?

Upvotes: 1

Views: 3949

Answers (3)

wunderdojo
wunderdojo

Reputation: 1027

Question is a year old but in case anyone else comes across it, thought I'd add this. I've actually been doing exactly what this person was attempting for a couple of years using Dropbox. I put the MySQL data files into a shared Dropbox folder and edit mysql.ini to let it know that they're not in the default location. The key to making it work successfully is starting / stopping MySQL when you switch between computers. If I'm working at home, for example, I'll fire up EasyPHP (using that instead of XAMPP). My htdocs are in a symlinked folder that is also shared via Dropbox. I do my work here, then shut down EasyPHP. When I go into the office, everything is sync'd and I fire up EasyPHP there.

On the occasion when I forget to shut down EasyPHP in one location or the other the db won't sync (the data file gets locked down, as the others noted) so I simply log into the other machine via LogMeIn, shut down EasyPHP and a minute or two later I'm good to go.

I'm sure there are plenty of reasons why this isn't the "right" way to do it but it's worked flawlessly for me with zero loss of data or errors.

Upvotes: 3

Namphibian
Namphibian

Reputation: 12221

In short this is not a good idea and I dont think it will be possible. The database files are essentially locked down as the database server needs to have exclusive access to it. There is no way sugarsync can know what state those files are in so it might actually copy half completed files from source to destination. It might even corrupt your databases completely as sugarsync might block access to the data file during a critical operation

If you need to keep synchronised copies of the databases here is some ideas for you.

  1. Good old fashioned back up and restore. If you dont need up to the date copies of your database you could schedule a backup once a day. Then use sugarsync to copy this file to the destination and then restore it.
  2. Replication. If you need the databases to be in synch at all times with minimal delay I would suggest you look at replication. This will allow you to replicate transactions from the one database to another.

Upvotes: 5

r0b0
r0b0

Reputation: 66

No, I'm afraid you can't just sync the database files using a file synchronization tool to keep the databases in sync.

Synchronization of databases is refered to as 'replication' and there is a whole chapter1 in the mysql manual dedicated to replication.

Upvotes: 0

Related Questions