Where are my MySQL database files on MacOS?

My 7-year-old MacBook got bricked. So I needed to recover some MySQL files from a Time Machine backup and load them onto a new computer.

And so I’ve been digging around finding out where all my homebrew and MySQL files are. While running mulitple instances of everything!

Here’s a fairly unstructured brain-dump of all that I’ve learned (or re-learned) along the way.

Includes using:

Requires: better than average command-line knowledge

Where is homebrew installed?

Turns out you can have multiple copies of homebrew installed.

The current default install goes to /usr/local/Homebrew

It seems that they may be moving the default install to /opt/homebrew on MacOS ARM/Apple Silicon processors. More…

If you run /some/homebrew/path/bin/brew then all operations will happen within that homebrew instance and not affect others.

Where are homebrew-installed MySQL/MariaDB binaries/executables?

Homebrew keeps package binaries in /some/homebrew/path/Cellar

So if you want to use a specific version of the mysql client you can do, for example: /some/homebrew/path/Cellar/mariadb@10.4/10.4.17/bin/mysql

Note that there is a notion of a “current” version that is symlinked into /some/homebrew/path/bin/

You can change the symlinked current version using brew link (make sure you use the right brew instance!)

Where are homebrew-installed MySQL/MariaDB data files?

The standard location for the database data files is /some/homebrew/path/var/mysql

Every version of MySQL/MariaDB installed in a particular brew instance appears to share the same location. Which is odd. This MUST be configurable from somewhere, but I didn’t get to finding out where it was. /some/homebrew/path/etc would be the obvious place. And there is a file there, but it doesn’t have much config in.

You’ll have to dig in to this to find out yourself. I would assume MySQL has some default location it’s reading from.

Starting and stopping MySQL/MariaDB using homebrew

Worth a quick note that you can start and stop homebrew-installed MySQL/MariaDB as a service using:

/some/homebrew/path/bin/brew services start <servicename>

e.g.

/some/homebrew/path/bin/brew services start mariadb@10.4

What even IS DBngin?

DBngin is a free MacOS app that lets you install/start/stop different databases. I figured all this out while I was moving to a new Mac and so thought I’d give it a go.

It’s limited in that it doesn’t include MariaDB yet. One of my big issues was – I think – incompatibilities between MariaDB and MySQL when reading data files.

Anyway…

Where are DBngin MySQL binaries?

DBngin puts binaries in /Users/Shared/DBngin/mysql/<version>

Where does DBngin put data files?

DBngin puts data files in /Users/<you>/Library/Application Support/com.tinyapp.DBngin/engines/mysql/<some ID>

I discovered while doing this migration that if there are not files called auto.cnf and com.tinyapp.DBngin.mysqld-<some ID>.plist in this directory then the whole directory will be wiped clean when you use DBngin to start up the database.

So if you empty this directory and copy a bunch of existing data files into it then you’ll immediately have them all deleted.

That…

is all I got!