Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

MySQL launchd item for Mac OS X Tiger (See related posts)

(Originally posted at Unquiet)

I had to reinstall Mysql because it wasn�t one of the things I backed up before erasing my hard drive. Since I�m now running Mac OS X 10.4 �Tiger�, I decided to set it up to start when the system boots, but the system for creating startup items has changed slightly. So I saved the following xml in /Library/LaunchDaemons/com.mysql.Mysql.plist:

<?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.mysql.Mysql</string>
        <key>OnDemand</key>
        <false/>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/local/mysql/bin/mysqld_safe</string>
        </array>
        <key>ServiceDescription</key>
        <string>Mysql 4.1 Database Server</string>
        <key>UserName</key>
        <string>mysql</string>
        <key>WorkingDirectory</key>
        <string>/usr/local/mysql</string>
    </dict>
    </plist>


Note that I'm using the official OSX distribution of MySQL... but with a few changes to match your database location, you can get this to work with other installs (fink, darwinports, etc).

Comments on this post

arnaud posts on May 30, 2005 at 19:02
Shouldn't the username be 'mysql', instead of 'root', in the case of a mysql setup as described at manuals.textdrive.com ?

springjp posts on May 31, 2005 at 19:52
Actually, for that there should be a '--user=mysql' parameter included. Running mysqld_safe under root is OK, I think.
rayKiddy posts on Nov 19, 2005 at 21:57

One should probbably add both:
    <key>UserName</key>
    <string>mysql</string>
    <key>GroupName</key>
    <string>mysql</string>

Stopping and starting the database should be done with:

sudo /bin/launchctl load -w <full-path-to-plist>

sudo /bin/launchctl unload -w <full-path-to-plist>
rayKiddy posts on Nov 19, 2005 at 22:07
Actually, the unload does not work. The mysqld_start starts another process, mysqld. If the plist was launching that, it could stop it, because a "kill -TERM" will work on that process, and that is what launchd does.

O well. It was worth a try.
claney posts on Jan 23, 2008 at 17:52
Thanks for this script, it's great. Worth noting there is an osx freeware app called lingon which is great for configuring launchd's. It's also got a nice gui for starting and stopping them so you don't have to do the command line thing!

You need to create an account or log in to post comments to this site.


Related Posts