Archive for January, 2011

Tutorial: Use DropBox to Share a Database (or any file)

Friday, January 14th, 2011

Admittedly, this is a niche problem, but it’s one I run into quite frequently. I have several development machines, and it used to be a huge pain in the but to keep my MySQL databases synced between them all so that I’m always working with the same data.

Enter DropBox and symbolic linking on the Mac (sorry Windows users).

In your DropBox folder, create a folder that will hold your shared databases. In recent versions of DropBox, you’ll want to ensure that this folder is not excluded from syncing on your target machines.

Quick steps:

  1. Back up your db files
  2. Move the db folder you want to share from your MySQL db directory to its DropBox counterpart
  3. Create a symbolic link from the DropBox version to your MySQL directory

Detailed steps:

On your primary development machine (or the one with the latest version of the database you wish to share), navigate to the folder containing your MySQL database files (For MAMP installations, this is typically /Applications/MAMP/db/mysql).

WARNING: BACK UP YOUR DATA BEFORE PROCEEDING!

Now move the folder containing the database you wish to share to your newly created counterpart in your DropBox folder. Move it, don’t copy it.

Fire up your terminal window. You’re going replace the folder you just moved with a symbolic link (not an alias!) from your DropBox version. DropBox folders can live anywhere you choose, so replace this example with your own paths:

ln -s /Users/Steve/Dropbox/Databases/example_db /Applications/MAMP/db/mysql/

Now you should see the DropBox version of your db folder there in the finder. Because it’s a symbolic link, MySQL is tricked into seeing the shared directory even though it’s no longer in your database directory.

Repeat this on every machine on which you wish to share this database.

Some caveats: this is a development solution only! Obviously, you will not use this technique on your live database! Also, this technique is susceptible to version control errors. Hence, it’s a good solution when you’re the only developer hitting the database files. My own use-case, for example, is syncing between my primary MacPro and my travel laptop. Your mileage may vary.

But wait! There’s more! This trick works with anything and any app, not just database files and MySQL. Give it a try. It’s yet another reason DropBox is one of the greatest services available on the Net today.

Sphere: Related Content