OS X uses launch daemons to automatically start, stop, and manage processes and applications such as MySQL. Using launch daemons is recommended over startup items on OS X.
OS X 10.4 deprecated startup items in favor of launchd daemons, and as of OS X 10.10 (Yosemite), startup items do not function. For these reasons, using launchd daemons is preferred over startup items.
Here is an example launchd file that starts MySQL:
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.mysql.mysqld</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/mysql/bin/mysqld_safe</string>
<string>--user=mysql</string>
</array>
</dict>
</plist>
Some users report that adding a plist DOCTYPE declaration causes the launchd operation to fail, despite it passing the lint check. For this reason, we have removed it from the example above.
Adjust the ProgramArguments array according
to your system, as for example your path to
mysqld_safe might be different. After making
the proper adjustments, do the following:
Save the XML as a file named
/Library/LaunchDaemons/com.mysql.mysql.plist
Adjust the file permissions using the Apple recommended owner "root", owning group "wheel", and file permissions "644"
shell> sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist shell> sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist
Enable this new MySQL service
shell> sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
The MySQL daemon is now running, and automatically starts when your system is rebooted.