Import Database from MySQL Dump on Vagrant Up?

The cheap quick and easy method I used with a colleague to make sure we were both working with the same data when collaborating on a project was to use the db_import option in wordpress_sites.

This will import the database on vagrant provision instead of vagrant up however it was enough for us both to have dummy data to work with whilst we developed the site and allowed us both to revert back to a working state if we made a mistake with something. It also means you can keep the dump in version control inside the project which may or may not be what you’re after.

Steps: (last tested on version 0.9.3)

  • vagrant ssh
  • cd /srv/www/example.com/current
  • wp db export # exports example_dev.sql to the site folder
  • Add the line db_import: ../site/example_dev.sql to wordpress_sites.yml

Updating the dump would have to be done manually but it’s as simple as ssh’ing into vagrant and running the export command again.

edit: updated the path for db_import, thanks for checking @ruslankomjakov

8 Likes