Sharing databases is something that’s convenient to do within your local development environment especially if you’re working with multiple machines.

If for whatever reason you’re looking to do this with a staging environment or production environment, then this is not the way to do it. There are strategies like database replication and the like that are meant for that, and that are far beyond the scope of this post.

Instead, this is primarily intended for systems that you have, likely on the same network, and that you swap between during the day.

Sharing Databases

First, the whole idea behind sharing databases is to make it easy to work with the same set of information across multiple machines when working on small-ish projects. Since databases are nothing more than [intelligently managed] files, they can be stored and synchronized in software like Dropbox.

Sharing Databases in Dropbox

Sharing Databases in Dropbox

Secondly, although the example that I’m going to give is specifically for MAMP Pro, this is applicable not only to MAMP but other systems as well. You just need to know where your software of choice keeps its database files.

Sharing Databases from MAMP

For MAMP Pro and on macOS, this is in the /Library/Application Support/appsolute/MAMP PRO directory. More specifically, it’s in the db subdirectory, but I’ll get to that momentarily.

And the idea behind sharing databases between (or among) machines is this:

  1. have Dropbox installed on each machine,
  2. have MAMP Pro (or your software of choice) installed on each machine,
  3. be comfortable with symbolic links (or shortcuts, if you’re on Windows).

Since I’m on macOS, the following set of instructions are going to be specifically for that, but they can be tailored for other machines.

1. Backup Your Data

This should go without saying, but anything that’s located in the /Library/Application Support/appsolute/MAMP PRO/db directory should be saved in case you make an error when setting up the shared resources.

To do this, copy (versus move) the db directory to another place on your hard drive so that you can easily restore it if something goes wrong.

2. Create a Location in Dropbox

This is up to you, but I’m a fan of using an “Apps” directory out of which I create shared settings. Sometimes this is for editors, other times it’s for software like Transmit (as you see in the shot above), and I’m using it for sharing databases, too.

Note, however, that the name of the directory is important – at least to a degree. I prefer the name the directory based on the directory that it’s going to represent as I create a link between the two files.

So, for example, in Dropbox, I have /Apps/MAMP/db since I have a db directory on the hard drive.

3. Copy the Database to Dropbox

From there, I copy the db directory from its original location on the hard drive to the location I’ve selected in Dropbox.

Databases in Dropbox

After that, I need to create a link.

4. Create a Symbolic Link

This is where things can break if you’re not careful. First, make sure MAMP is completely closed. Note that the syntax for symbolic links takes the destination directory first then the source directory second.

Symbolic Links

Next, I usually remove the db directory from its original location. This isn’t something that has to be done, but I find it cleaner to start without anything in the MAMP directory such that when I create the symbolic link, that’s what it creates.

So open a Terminal window and enter the following command:

After that, verify your Dropbox directory contains the database files, as expected, and that your db directory in MAMP is referencing an external directory (it will have an arrow overlay on it like this):

External Database Reference

External Database Reference

Again, With the Local Environments

To reiterate, this is something that I recommend only for local environments and something that I think you should do only if you aren’t dealing with sensitive data.

A Note From a Reader

Specifically, make sure that when you’re setting this up, you have your servers off. And when you move to a another machine, you turned MySQL off on the original machine.

Back on Target

Database replication across other machines is best left to the experts, and sharing sensitive information should be self-evident as to why this shouldn’t be stored in Dropbox.

Other than that, once all is said and done, load MAMP on your machines and you should see all of your data available across each machine and accessible from your favorite database front-end.