Starting and restarting MySQL
I’ve had adequate opportunities to install/reïnstall MySQL in the past year that I’m starting to find what the hiccups are. Oracle can’t seem to figure out how to reliably start/restart/stop MySQL in Mac OS X. The control panel (sorry, preference pane) is really only adequate for telling if the server is running or not. Trying to actually start the server using Oracle’s preference pane fails, and the check box to start automatically doesn’t work, either.
What does work, in 10.6 Snow Leopard, is using launchd to manage the starting and stopping of MySQL.
Most of these details are from Dan Benjamin’s website, hivelogic, where he advocates rolling your own MySQL from source. I’m not opposed to compiling from source, but lacking a need for it I find these instructions work just as well for the pre-compiled MySQL from Oracle.
Anyway, first you’ll need a plist file for launchd to use to start and stop MySQL. I’m not sure if mine originally cam from Dan’s page, but it’s identical anyway.
Save the following as com.mysql.mysqld.plist.
!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>com.mysql.mysqld</string>
<key>Program</key>
<string>/usr/local/mysql/bin/mysqld_safe</string>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>mysql</string>
<key>WorkingDirectory</key>
<string>/usr/local/mysql</string>
</dict>
</plist>
The next step is to get the Mac to do something with this
plist file. Copy or move it to /Library/LaunchDaemons/
I don’t know how important these settings are to the function, but I set the owner of the file to root and tightened the privs a bit:
sudo chown root.wheel /Library/LaunchDaemons/com.mysql.mysqld.plist
sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysqld.plist
Finally, to start MySQL, enter the following:
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist
Stopping MySQL can be accomplished with this command:
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist
The last thing that needs doing is to set the root user’s password for MySQL:
mysqladmin -u root password NEWPASSWORD







