# Vagrant database setup

**URL:** https://discourse.roots.io/t/vagrant-database-setup/1153
**Category:** archived 🗄
**Created:** 2014-01-29T20:13:49Z
**Posts:** 7

## Post 1 by @Jaace — 2014-01-29T20:13:49Z

Bedrock isn’t up and running with Vagrant yet and since I’m trying to work Vagrant into my workflow, I have a “best practices” type of question. I’m sure will be answered once Vagrant is worked into Bedrock, but in the meantime:

I didn’t find any detailed info on how best to maintain a MySQL (or any, really) database using Vagrant. If I were to simply destroy my vagrant VM (since I’m done with a project, let’s say) and I want to keep the sql from the development site, how best to go about doing that?

Should I just go about backing it up to a folder or is there a more elegant way? Ideally there would be some way to have a vagrant command or at least a shell script to dump the database to a folder in my project directory before destroying the VM.

Anyway, just looking for some suggestions, thanks!

---

## Post 2 by @swalkinshaw — 2014-01-30T17:56:48Z

Not really sure about best practices for this. That seems like a use case that wouldn’t happen too often so I’d just probably just do it manually when needed. Just running a `mysqldump` on the VM and write it to your shared local folder.

---

## Post 3 by @wynnepirini — 2014-02-01T07:04:45Z

This might help you (in development stage, at least).

Create a folder called **db** in your project folder.

Then in your **Vagrantfile** add this line:

```
config.vm.synced_folder "db/", "/var/lib/mysql/db_wp", disabled: false
```

(That’s the correct location for Ubuntu).

Rename **db\_wp** to whatever you want to call your db.

When you first **vagrant up** the folder will be empty. But if you will see the db is in there (but it’s empty).

Import your sql file into that folder. After that you’ll see the files extract to uncompressed sql files.

Now when you destroy your VM, you’ll still have your sql files in place. No need to reimport them everytime.

Hope this helps.

---

## Post 4 by @Jaace — 2014-02-01T14:48:03Z

Thanks wynnepirini, I will try that!

---

## Post 5 by @theherounit — 2014-02-04T23:47:03Z

hi, i’m trying to do the same thing manually just so i can get an understanding of what is going on as server side stuff isn’t my strong point. but i’m having difficulties getting wordpress to run.

what i’m doing at the moment is using a simple [shell script](https://gist.github.com/ChrisYip/5539984) to provision my VM with a LAMP stack but i have absolutely no idea what the db\_name, user and password is so i can fill in the wp-config.php file?

I’ve been playing around in the VM using ssh but i can’t seem to find out how to check my DB name, user and password or even if one exists.

---

## Post 6 by @kalenjohnson — 2014-02-05T04:13:13Z

How did you set up your Vagrant VM? If you set everything up manually, then you should have set a password for the root mysql user when it was set up.

If you downloaded a Vagrantfile from somewhere, it should probably say somewhere inside the Vagrantfile or possibly the Puppet/Chef/Shell script it uses to provision the server.

---

## Post 7 by @swalkinshaw — 2014-02-05T04:37:08Z

Going by that shell script:

`db_user` = `root`  
`db_password` = `PASSWORD`

You’d need to create a database first using those credentials, then use that db name for `db_name`.

Example: `mysql -u root -e "create database wp_site_name;"`

---

## Post 8 by @ben — 2022-02-26T03:20:49Z


