1

I've installed MySQL via homebrew and these instructions. The service that homebrew installs is a LaunchAgent, which works fine but only runs while the my user is logged in. I want MySQL to be running at all times.

I've tried copying homebrew.mxcl.mysql.plist to /Library/LaunchAgents, setting permissions to 644 root:wheel, and loading with sudo launchctl -w /Library/LaunchAgents/homebrew.mxcl.mysql.plist. Although sudo launchctl list shows that the plist is loaded and the status is 0, there is no PID. When I run ps aux | grep mysql, I do not see any related processes.

Running the command manually works: /usr/local/opt/mysql/bin/mysqld_safe --datadir=/usr/local/var/mysql --bind-address=0.0.0.0 but then MySQL will quit if the user logs out.

There is a related question on stackoverflow already but it seems like everybody is answering how to add the service via LaunchAgent, which runs at login rather than at boot.

/Library/LaunchDaemons/homebrew.mxcl.mysql.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>KeepAlive</key>
  <true/>
  <key>Label</key>
  <string>homebrew.mxcl.mysql</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/opt/mysql/bin/mysqld_safe</string>
    <string>--datadir=/usr/local/var/mysql</string>
    <string>--bind-address=0.0.0.0</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>WorkingDirectory</key>
  <string>/usr/local/var/mysql</string>
</dict>
</plist>

ps aux

nperkins$ sudo ps aux | grep mysql
nperkins        15345   0.0  0.0  2444056    816 s001  S+    7:02PM   0:00.00 grep mysql

Launchctl list

nperkins$ sudo launchctl list | grep mysql
-   0   homebrew.mxcl.mysql
Nathan Perkins
  • 131
  • 3
  • 7

1 Answers1

0

I figured this out. The LaunchDaemon plist was running and trying to keep alive every five seconds, but mysqld_safe was choking on start because the data folder, /usr/local/var/mysql, was not in _mysql group. I changed the ownership of that folder to _mysql:wheel and now it works.

Nathan Perkins
  • 131
  • 3
  • 7