Skip to content

Instantly share code, notes, and snippets.

@laalaguer
Last active June 14, 2025 04:23
Show Gist options
  • Save laalaguer/f932e2dd3dccb82c32917606db99aeb3 to your computer and use it in GitHub Desktop.
Save laalaguer/f932e2dd3dccb82c32917606db99aeb3 to your computer and use it in GitHub Desktop.
Moving MySQL data directory to external disk

Sometimes database is too large for Mac's internal disk. Moving data directory to an external HDD disk is required, and here is how.

Environment

  • Mac Mini 2025 (M4 chip) + HDD external drive formatted with APFS (defaut: case insensitive).
  • MySQL version v8.0.42.
  • Data ~200GB.

Failed Attempts

I tried GUI panel (Mac Settings > MySQL > Configuration Tab > Data Directory). Once you hit start the server button it went green then quickly turned red.

It turns out that any time you edited (sudo) the /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist, it got reflected on the GUI and vice-versa. But it doesn't improve the situation and can't view the log file of failed launch. I can't determine if there was a wrong config caused problem that didn't get updated on lauch or simply the error on the permission of folders.

What was Really Wrong with Ownership/Permission on Mac OS

Mac OS by default doesn't set file/folder owner on external disks for maximum compatibility. However it can cause a problem since our MySQL setup requires data folder to be of permission user:_mysql and group:_mysql. Each time i execute:

sudo chown -R _mysql:_mysql folder_name it doesn't yield error, but also doesn't work at all.

You can verify if your external disk supports owner by (Disk Utility > your-disk-name > look for "Owners")

It turns out you need to enable it in the GUI.

(Finder > Right Click on disk > Get Info > scroll down > Uncheck "ignore ownership on this device"), you may click the lock icon to allow changes, and also review who can "Read and Write" the disk.

Now do the sudo chown -R _mysql:_mysql folder_name again and it works.

Move Data

Move the data directory into the HDD disk, I used following:

sudo mv /usr/local/mysql/data /Volumes/your-disk-name/your-location

It worked. Upon double check the original data folder and moved one, the ownership _mysql:_mysql kept.

Launch MySQL

I tried GUI again, fill in the changed three variables accordingly: the --datadir, --log-error and --pid-file.

It doesn't work. The indicator turned green then quickly went red.

So instead, I directly launched it via terminal.

sudo /usr/local/mysql/bin/mysqld \
  --datadir=/Volumes/HDD-disk/.../data \
  --plugin-dir=/usr/local/mysql/lib/plugin \
  --early-plugin-load=keyring_file=keyring_file.so \
  --keyring-file-data=/usr/local/mysql/keyring/keyring \
  --log-error=/Volumes/HDD-disk/.../data/mysqld.local.err \
  --pid-file=/Volumes/HDD-disk/.../data/mysqld.local.pid \
  --user=_mysql

Three options were changed correspondingly, the --datadir, --log-error and --pid-file and leave others untouched.

Then I connected it via mysql -u root -p.

When I go back to check on the GUI panel after several minutes, the indicator is green, too. The GUI panel is still broken in the terms of "start the server" button is still not working. But now using command line tool to start/stop MySQL is already enough for my development workflow.

Stop MySQL

Use sudo kill -TERM "$PID" with the pid from the pid file mentioned earlier in launch to stop MySQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment