Sharing databases is something that’s convenient to do within your local development environment especially if you’re working with multiple machines.
How to sync your hosts between different Macs using Dropbox.
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.
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.
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. Download zmin printers driver.
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:
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.
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.
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.
From there, I copy the db
directory from its original location on the hard drive to the location I’ve selected in Dropbox.
After that, I need to create a 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.
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
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.
you also want to make sure only 1 machine has MySQL service running at a time.
— Scott Lesovic (@gMagicScott) February 15, 2017
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.
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.