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, it is currently used in Leopard and is the prefered way in controlling your deamons.
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:
<!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.
The RunAtLoad means it will start at boot time.
The UserName option indicates under which user the program should start.
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:
You can see if it loaded correctly by using the command:
This will show you all the active plist files.
If everything went correctly mysql has already started.
To stop the instance you could use:
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.



1:29 pm
I found some warnings with the mysqld_safe script :
com.apple.launchd[1] (0x1001074d0.anonymous.nohup[2244]) Bug: launchd_core_logic.c:8301 (24003):0
com.apple.launchd[1] (0x1001074d0.anonymous.nohup[2244]) Switching sessions is not allowed in the system Mach bootstrap.
com.apple.launchd[1] (0x1001074d0.anonymous.nohup[2244]) _vprocmgr_switch_to_session(): kr = 0x44c
com.apple.launchd[1] (0x100416fe0.anonymous.nohup[2245]) Bug: launchd_core_logic.c:8301 (24003):0
com.apple.launchd[1] (0x100416fe0.anonymous.nohup[2245]) Switching sessions is not allowed in the system Mach bootstrap.
com.apple.launchd[1] (0x100416fe0.anonymous.nohup[2245]) _vprocmgr_switch_to_session(): kr = 0x44c
To resolve it, I launch mysqld directly :
Label
com.diymacserver.mysql
Program
/usr/local/mysql/bin/mysqld
ProgramArguments
–user=_mysql
RunAtLoad
KeepAlive
UserName
_mysql
GroupName
_mysql
Umask
7
WorkingDirectory
/usr/local/mysql
If this can help somebody…
5:17 pm
@wpicz, I also get the warnings but MySQL still runs properly after restarting the machine or killing mysql. If you run /usr/local/mysql/bin/mysqld then you will not start the latest version you compiled.
7:44 pm
If you run /usr/local/mysql/bin/mysqld then you will not start the latest version you compiled. I don’t understand why ? all seems ok :
mysql> \s
————–
mysql Ver 14.14 Distrib 5.1.45, for apple-darwin10.3.0 (i386) using readline 5.1
8:32 pm
@wpicz, this is only true if you’ve upgraded to a later version by compiling from source. The file /usr/local/mysql/bin/mysqld is not touched after updating.
The mysqld program referenced in the mysqld_safe script is located in /usr/local/mysql/libexec/ which is updated.
12:00 am
Ok, it’s good to know !
It is possible to launch directly /usr/local/mysql/libexec/mysqld with launchd or the mysql_safe get another possibilities or more technicalities ?
11:23 am
I found my response : http://dev.mysql.com/doc/mysql/en/mysqld-safe.html
Some warnings is not evil…
2:23 pm
If you want to delete in spite of everything this warnings, You can change it at your own risk the mysql_safe script : comment the complete condition “nohup nice > /dev/null 2>&1″ and insert after this instruction : NOHUP_NICENESS=”"