Sometimes database is too large for Mac's internal disk. Moving data
directory to an external HDD disk is required, and here is how.
- Mac Mini 2025 (M4 chip) + HDD external drive formatted with APFS (defaut: case insensitive).
- MySQL version v8.0.42.
- Data ~200GB.
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.
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 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.
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.
Use sudo kill -TERM "$PID"
with the pid
from the pid file mentioned earlier in launch to stop MySQL.