1. Freebies
  2. Tutorials
  3. Dropbox Database Sync for Testing
Dropbox Database Sync for MySQL & MAMP

Dropbox Database Sync for MySQL & MAMP

Using Dropbox for web development is an easy way to share files across multiple local servers. This tutorial shows you how to setup a Dropbox database sync so you can trigger your MySQL database sync in the push of a button.

Keeping computers in a local testing environment in sync can be a nightmare. While using GIT is certainly preferential, it may not be an option for newbies of those without the needed experience or software. In those cases, creating a file and Dropbox database sync is an ingenious option. As long as you have MAMP and Dropbox on your computer, you'll be able to share your files and databases across any computer you'd like to run a local testing environment on.

We will start off assuming your testing environment is already established. If you haven't gotten to that step yet, please refer to our Setting up MAMP. MAMP (much like LAMP or XAMP) is simply an acronym for Apache, MySQL, PHP and it's important to keep that in mind while we push forward. What we're looking to address in this tutorial is your MySQL database. More specifically - We will be creating a SQL database on Dropbox then tricking MAMP into using that (instead of the default /db folder).

Create a Dropbox Account

Dropbox is an amazing tool, even if you're not a dev nerd. You can get started by setting up a free account at http://www.dropbox.com, but put simply - Dropbox is just online "cloud" storage that is easily accessible through multiple devices. Once your account is properly setup and assuming you already have MAMP installed, we can move forward to create your local Dropbox database sync. This is what we'll be able using to ensure that databases are properly disseminated to all the computers that will be sharing the local testing environment.

Creating your Dropbox Database

Open your Terminal application that's located in your "Applications/Utilities" folder. Make sure you're MAMP server is off, then we'll be running a few commands to achieve the following tasks for the files you'll be using on your local server.

Each of the above tasks are achieved with the corresponding Terminal commands below. Keep in mind that if your file structure is different, you will need to adjust the folders to suit your individual needs. As with everything in Terminal, be deliberate and take your time. Also note that the name "MAMP_DATABASE" is arbitrary. If you prefer a different name feel free, just make sure you use the exact same name in both lines (2nd & 4th) and adhere to the normal naming rules (alphanumeric and underscores).

cd ~/Dropbox/
cp -r /Applications/MAMP/db MAMP_DATABASE
rm -rf /Applications/MAMP/db
ln -s ~/Dropbox/MAMP_DATABASE/db /Applications/MAMP/db 

Once you've got everything setup, clear your browser cache, and start your MAMP application. If you get an error I'd suggest clicking on your PHP admin tab, since most errors will result in a missed connection there. As long as everything is up and running, give one last sync, and then we'll get next computer connected.

Initialize Your Dropbox Sync

MySQL Database Sync - MAMP File Structure

Make sure your MAMP server is off (you obviously don't want to sync your database while it's on) then start your Dropbox application. Give a quick look to your file structure to ensure the above Terminal commands were entered properly. Just look at your Applications/MAMP folder and make sure it matches up. You should see the small folder icon with the arrow underneath (see image) where your db folder used to be. In your Dropbox folder you should see your new database folder, which in this example would be named MAMP_DATABASE. Since your SQL database is in your Dropbox folder, you just sync Dropbox, and you're good to go.

Adding Computers to your Dropbox Database Sync Environment

The Terminal commands we used earlier are useful in this situation, but we certainly don't want to overwrite the existing Dropbox database - We just want to use it. While these commands look similar, that is the crucial distinction between them. In this case the tasks we're trying to achieve areā€¦

Each of those tasks will be achieved with the corresponding Terminal commands below.

cd ~/Dropbox/
rm -rf /Applications/MAMP/db
ln -s ~/Dropbox/MAMP_DATABASE/db /Applications/MAMP/db 
Enjoy Your Coordinated Local Development Setup

Dropbox for Web Development - Dropbox Database Error

That's it - Not as tricky as you thought right? If you do happen to run into any issues (and if you're a newbie, you might) just make sure you take a look at your error logs and the structure of your folders. The only issue's I've seen in using this setup is the normal "conflicting copy" errors that you occasionally get with Dropbox (see image). As long as you only sync one computer at a time, this shouldn't be a problem. If you do see those errors, just make sure you delete the appropriate "conflicting" files, and you're good. If anything looks really wonky, just double check your file structure cause it may be an input error with those terminal commands.

Now throw the first person you see a high-five, because you have an AWESOME tool for your testing environment. No more importing, exporting, and ending up with spare database backups everywhere. As previously mentioned, moving to a GIT workflow (like we covered in this post > Optimizing Development Workflows) is a much better approach, but this works for beginners or if you need something quick.

If you have any questions or ideas on how to flush out this concept, please feel free to shoot us a message and we'll fold it in. If you found this tutorial helpful, please share with any of the buttons below or give us a follow on your favorite social network. As always - Thanks for stopping by and happy coding!!

Related Articles
  • 10 Responsive Frameworks You Need
    Bootstrap vs UIKit vs Foundation - We take a look inside all the popular frameworks on the market and find the 10 Responsive Frameworks You Need.
    10 Responsive Frameworks You Need
  • 20+ Top Free Ghost Themes
    In the battle for CMS supremacy, Ghost has made waves as a solid ultralight option. Like any other web tool it does need to look good though, that's why we compiled the top free Ghost themes for newbies & pros alike.
    20+ Top Free Ghost Themes
  • Dropbox
    Some terms scare people off. Cloud computing may seem like some far off, nerd driven technology. Dropbox makes it easy as pie.
  • How to use MAMP: Setting up MAMP
    Utilizing a local development environment is crucial for web developers, but it's not well documented. This guide to setting up MAMP will show you how to create your own PHP development server & how to use MAMP efficiently once you're all setup.
    How to use MAMP: Setting up MAMP
  • Mobile Editing Apps - iOS Code Editors
    The best Mobile Editing Apps and iOS Code Editors contain an amazing power - Allowing you to actually take your web development skills on the road.
    Mobile Editing Apps - iOS Code Editors
  • Optimizing Development Workflows
    Efficient workflows and workflow patterns are key to effective web development. Learn how to streamline your workflow with this web development tutorial.
    Optimizing Development Workflows
Written By:
Matthew Haeck

Greetings, I'm the lead designer and resident full stack web developer at Haeck Design. A majority of my time is spent creating beautiful logos, websites, print design, & staying up to date on all the tricks of the web development trade. (Matthew Haeck Bio Page)

Haeck Design - Stamp Logo