Where are database files stored?

In older versions, there was a directory with all the database files in sitename/app/sql/. This is missing in newer versions. Any idea where they are now?

Hey Michael,

The raw SQL data is inside the container in /var/lib/mysql

As far as SQL files go, they are automatically placed into the site folder under /app/sql whenever you trigger the site to stop. We have plans to make automatic backups to /app/sql outside of stopping the container.

I don’t have the /var/lib/mysql/ directory on my system. Could the db files be somewhere else? I’m trying to restore from a backup and I need access to the actual files.

All I have is /var/lib/postfix — no mysql directory.

J

I should say no mysql directory or file in /var/lib/

And this is on macOS.

@joshuaiz,

/var/lib/mysql is inside the site container. To see it, you’ll need to right-click on the site in Local and go to “Open Site SSH”

Are there MySQL files in the site’s app/sql folder when you look in Finder?

1 Like

Ok was able to locate that directory through SSH but how can I copy these files logged in as root to the Finder to use as a restore?

Also, is there a way to access these at all through Finder as I want to grab a Time Machine backup of these files. If I can’t do that, then I’m stuck anyway.

And yes there are files in app/sql but they are from before when I need to restore from. As I read those are only written if the site is stopped in LOCAL.

Thanks!

Ok was able to locate that directory through SSH but how can I copy these files logged in as root to the Finder to use as a restore?

Yup, you can leverage the /app directory to do this. You can run cp -r /var/lib/mysql /app and a mysql folder will show up in /app in Finder.

Also, is there a way to access these at all through Finder as I want to grab a Time Machine backup of these files. If I can’t do that, then I’m stuck anyway.

No, but if you can restore ~/.docker/machine/machines/local-by-flywheel/disk.vmdk to the point in time that you need you can follow the instructions above to get to the files.

This is awesome. I was able to get a backup from WP Engine so I’m all set however if I restore the docker volume that will overwrite all of my sites, correct?

Just want to make sure in case I need this in the future.

Thanks so much for the help.

Yup, that’s correct. It will modify every other Local site—primarily the databases and containers. The site files themselves shouldn’t be changed.

I would recommend exporting all of your existing Local sites prior to going down this path.

@clay Howdy! Since this thread is (almost) 2 years old, I’m just confirming I understand correctly:

  1. The live database in the VM is backed up to ~/Local\ Sites/site/app/sql each time the VM is powered down?

  2. While the VM is powered down, if I restore the files written to that directory (~/Local\ Sites/site/app/sql) from backup, then LOCAL will rebuild the database from those files when the VM restarts?

@jamesfinn, in my tests, this is not the case. I created a test site in Local, stopped the site to trigger the SQL exports, modified the options table SQL and restarted the site. This did not import the changes I made to the options table and when I stopped the site again, my changes were reverted in the /site/app/sql files.

It appears that though this is a backup location when the VM is stopped, it is not restored from that location when the VM is started back up. Hope that helps.

2 Likes

@mattwhosthat Roger that. Thanks.