Richard
The official startup script provided by MySQL is the old fashioned way of starting programs during startup. Apple however has decided that this will stop in future versions and that they will move over to launchd. This is currently used and is the preferred way in controlling your daemons.
To enable it we need to create a .plist file with all the details, as MySQL is a system wide application we need to put it in /System/Library/LaunchDaemons/ and I’m going to call it com.diymacserver.mysql.plist. The content of the file will look like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.diymacserver.mysql</string>
<key>KeepAlive</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/mysql/bin/mysqld_safe</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
The label key should be the same as the plist file name without the .plist. The KeepAlive option will restart MySQL when it crashes or is stopped. RunAtLoad means it will start at boot time.
To load and activate the .plist file and to make sure that it is started after a reboot you’ll need to load the plist file by using the command:
sudo launchctl load /System/Library/LaunchDaemons/com.diymacserver.mysql.plist
You can see if it loaded correctly by using the command:
sudo launchctl list
This will show you all the active plist files. If everything went correctly MySQL should have started. To stop the instance you could use:
sudo launchctl stop com.diymacserver.mysql
But because of the KeepAlive option it will be restarted. To stop the script being run at boot time you need to unload the plist file.
sudo launchctl unload /System/Library/LaunchDaemons/com.diymacserver.mysql.plist



Comments
11:23 am
For some reason, mysqld_safe didn’t start in Lion 10.7.2 but
root# ./bin/mysqld -u root was able to start. So it ‘s obviously a permission/ownership problem, which I have verified in error message, too. I’ve -R chowned the ./data to _mysql:wheel and then mysqld_safe worked.
Just for your information.
5:58 pm
Question, how did you install MySQL.
2:12 pm
I’ve installed not by using the .dmg package, but by downloading the tar (mysql-5.5.19-osx10.6-x86_64.tar) and extracting it into /usr/local/ and making a symbolic link to it as /usr/local/mysql.
6:44 pm
That explains, we advise to use the DMG image as it will install everything with the correct permissions so you won’t have the problems you encountered.
2:20 am
You mention, The UserName option indicates under which user the program should start. but I don’t see that in the script in this page. Could you point out the syntax and where it should be?
7:19 pm
@Greg, sorry leftover from an earlier version it’s update. You set the username correctly when editing the mysqld_safe script which is started by this as root.