Auto-Start MySQL on OSX 10.10 Yosemite

2.3k views Asked by At

I have installed MySQL using homebrew (brew install mysql) to work with my Rails application. Upon completion, I got a fairly detailed setup guide to configure the MySQL server, however it was missing information on how to configure MySQL to start following boot.

To use MySQL, I must manually execute the following at the OSX Terminal:

  • cd . ; /usr/local/Cellar/mysql/5.6.25/bin/mysqld_safe &

Using the instructions from this StackOverflow answer, I created an almost identical file, replacing the installation path with mine, but that didn't work as MySQL wasn't running after rebooting. I also noticed that I was missing the mysqld_safe file as can be seen in those instructions. I assumed those instructions wouldn't work for me as the OP there upgraded while I was on a new machine / OS installation.

Part of the instructions I got following installation stated:

To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system.

I have found mysql.server at /usr/local/Cellar/mysql/5.6.25/support-files and I can also use that to start, stop and check the status of MySQL by running /path/to/file/mysql.server with the required function. However I don't know where the "right place" is on my system like the instructions put it.

-- How can I auto-start MySQL on my Mac running 10.10 after installing MySQL with brew? Is there a file similar to rc.local (on Linux) where I can put the startup command? Any help with this one?

-- UPDATE -- I found mysqld_safe at /usr/local/Cellar/mysql/5.6.25/bin/mysqld_safe and after creating a new .plist file as explained in the MySQL Launch Daemon tutorial with --user set as mysql and also tried with _mysql, it still doesn't start MySQL following boot.

/Library/LaunchDaemons/com.mysql.mysql.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>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>com.mysql.mysqld</string>
    <key>ProgramArguments</key>
    <array>
    <string>/usr/local/Cellar/mysql/5.6.25/bin/mysqld_safe</string>
    <string>--user=mysql</string>
    </array>
  </dict>
</plist>

I should note that either of the following commands start MySQL following boot:

  • /usr/local/Cellar/mysql/5.6.25/bin/mysqld_safe &
  • /usr/local/Cellar/mysql/5.6.25/support-files/mysql.server start
3

There are 3 answers

3
NRJ On BEST ANSWER

When I did - brew info mysql, it mentioned that I can use the following command to auto-start mysql on boot -

ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

I did and the mysql has been auto-starting on boot on my OS X 10.10.3 Yosemite

0
sybind On

From the, brew info mysql documentation, it says:

To have launchd start mysql now and restart at login:

brew services start mysql
0
Neal.Marlin On

If you had ever read the brew manual, you would probably know that. Tap brew services, you'll see "Integrates Homebrew formulae with OS X's launchctl manager. Services can be added to either /Library/LaunchDaemons or ~/Library/LaunchAgents. Basically, items in /Library/LaunchDaemons are started at boot, while those in ~/Library/LaunchAgent are started at login. When started with sudo, it operates on /Library/LaunchDaemons; otherwise,it operates on ~/Library/LaunchAgents". Hope this maybe help.