How To Start MySQL at Startup on OS X Yosemite

How To Start MySQL at Startup on OS X Yosemite

This solution, how to start MySQL at startup on OS X Yosemite, is taken from this StackOverflow thread. I’m putting the solution here so I don’t have to keep googling it.

This is all command line stuff, so you’ll need to open Terminal in Applications -> Utilities -> Terminal.

First, we need to create the following file:

$ sudo vi /Library/LaunchDaemons/com.mysql.mysql.plist

Insert the following into the file:

<!--?xml version="1.0" encoding="UTF-8"?-->
<plist version="1.0">
  <dict>
    <key>KeepAlive</key>
    <true />
    <key>Label</key>
    <string>com.mysql.mysqld</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/mysql/bin/mysqld_safe</string>
      <string>--user=mysql</string>
    </array>        
  </dict>
</plist>

Then:

$ sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist
$ sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist
$ sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist

The next time you reboot, MySQL will automatically start. On some systems, the last command will actually start MySQL if it isn’t running. I’ve had mixed and weird luck with this.