3

I'm trying to automatically start mysql 5.5.10 community server (gpl) on my mac pro. I've read several threads on this forum. I'm still baffled, because those threads refer to a file:

/Library/StartupItems/MySQLCOM

I don't seem to have this file or folder.

Can someone please help.

btw, I can start mysql using mysqld...and it works fine.

Thanks in advance!

hba
  • 7,406
  • 10
  • 63
  • 105

2 Answers2

14

You actuall have to create this file... Best way is with a symlink:

mkdir /Library/StartupItems/MySQLCOM
cd /Library/StartupItems/MySQLCOM/
ln -s /path/to/installation/mysql/support-files/mysql.server MySQLCOM

However I wouldnt recommend this. You should do it proper and use launchd instead - this is the proper OS X way :-)

First create a plist at /Library/LaunchDaemons/com.mysql.mysqld.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <false/>
    <key>GroupName</key>
    <string>_mysql</string>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>com.mysql.mysqld</string>
    <key>Program</key>
    <string>/usr/local/mysql/bin/mysqld</string>
    <key>ProgramArguments</key>
    <array>
        <string>--user=_mysql</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>Umask</key>
    <integer>7</integer>
    <key>UserName</key>
    <string>_mysql</string>
    <key>WorkingDirectory</key>
    <string>INSTALL_PATH/mysql</string>
</dict>
</plist>

Then an adjust the permission:

sudo chown root /Library/LaunchDaemons/com.mysql.mysqld.plist
sudo chgrp wheel /Library/LaunchDaemons/com.mysql.mysqld.plist
sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysqld.plist

Now MySQL should be launched on startup. To test that everything works without rebooting you can run: sudo launchctl load com.mysql.mysqld.plist then check your error logs for messages.

IF you need to add special args (like custom logs, cnf, etc..) you can do so by specifying them as <string> elements in the <array> element following <key>ProgramArguments</key>. The values of those <string> element should be the standard switches you would use with mysqld.

prodigitalson
  • 60,050
  • 10
  • 100
  • 114
  • That worked! Thanks for introducing me to lunchd...I have a lot of catching up to do. One minor fix: the ".plist" is missing from the change authorization commands. Also I was not able to set the StandardErrorPath /var/log/mysqlerr.log. In Console.app it said too many parameters? Thanks again! – hba Apr 08 '11 at 12:39
  • One other thing...I had to change the ownership of all my data files and folders to _mysqld. – hba Apr 08 '11 at 12:42
  • @hba: Odd, I've never modified that but it should be a valid option for launchd... (fixed the chown/mod paths as well - good catch... sorry about that) – prodigitalson Apr 08 '11 at 15:05
  • Is it normal on startup to seem multiple mysqld processes and then eventually only one? Is there a way to prevent this? – Chris Muench Dec 22 '13 at 19:03
1

A slight change to how to install the plist for newer versions of OSX.

Instead of simply creating the file in the LaunchDemons folder and modifying permissions, create the plist file in a local folder and then run: sudo install com.mysql.mysqld.plist /Library/LaunchDaemons