Losing data in Vagrant after restart or destroy

database, mysql, vagrant

Solution

In my opinion, the answers to your questions depend on how you set up the project. On a project that I work on our set up is the following (simplified):

- database server (cloud hosted)

- origin server (cloud hosted)

- vagrant box for local development

- git repository

- ...

On `vagrant init` each developer gets a copy of the environment which is a ubuntu server. All application code (website) is mounted into the virtual machine from your local file system. We keep this application in the git repository. Then we keep a few scripts inside the vagrant machine that synchronize the database from the production (or demo server) - basically it downloads the database dump file and places it into your virtual machine.

In that case, if you do `vagrant destroy` and then `vagrant init` you need to run the database sync script to get the databse back. Our developers (mostly) don't change the content of the database so we don't need to keep the local changes.

I hope that this helps a bit.

Problem

I am new to Vagrant and have a couple of questions. Sometimes when I restart my computer or destroy my vagrant the whole MySQL database is wiped out. I tried to find some answers about this on stackoverflow but didn't have any luck so far. So my questions are: 1) Where does the data get stored? 2) Why do I sometimes lose data? 3) If so how do I keep the data after restart of destroy?

Original source