OSX Launching mysql at startup in Yosemite

This assumes that you installed mysql using homebrew (ie. brew install mysql)


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

# to manualy start the service
# sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.mysql.plist

Gotta make sure it's got the right permissions:
sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
sudo chmod 644 /Library/LaunchDaemons/homebrew.mxcl.mysql.plist


Contents of the homebrew.mxcl.mysql.plist file:


  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple
  3 <plist version="1.0">
  4 <dict>
  5   <key>KeepAlive</key>
  6   <true/>
  7   <key>Label</key>
  8   <string>homebrew.mxcl.mysql</string>
  9   <key>ProgramArguments</key>
 10   <array>
 11     <string>/usr/local/opt/mysql/bin/mysqld_safe</string>
 12     <string>--user=root</string>
 13     <string>--socket=<socket filepath></string>
 14     <string>--pid-file=<pid filepath></string>
 15     <string>--bind-address=127.0.0.1</string>
 16     <string>--datadir=<data directory></string>
 17   </array>
 18   <key>RunAtLoad</key>
 19   <true/>
 20   <key>WorkingDirectory</key>
 21   <string>/usr/local/var</string>
 22 </dict>
 23 </plist>

Reinstalling homebrew (Yosemite update)

# clean up homebrew
rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

# reinstall homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

# recommended
brew doctor
cd /usr/local/Library && git stash && git clean -d -f

now you can start clean again with homebrew:

ie. brew install mysql

MySql Hell: error! the server quit without updating pid file

First I have to note that several other developers have recommended removing the .err file, or renaming the ib_logfile## files. Obviously this didn't work for me or else I wouldn't be writing this post.


This issue started occurring once I placed my.cnf into the /etc directory.

The best way to see what's actually happen is to open the err file and debug. You can specify the location of the log file via:

[mysqld]
datadir = /usr/local/mysql

With the above setting, your log file will be:
/usr/local/mysql/.err



In my case it was actually a permissions issue. My database uses a non-standard socket setting (to match linux environment). I also disabled the root access, and have specific credentials that mysqld and mysql needs during startup. That said, my my.cnf file looks as follows:

[client]
user=myuser
password=mypassword

[mysqld]
user=sysuser
pid-file=/path/to/mysqld.pid
socket=/path/to/mysqld.sock
port=3306
datadir=/dir/for/mysql/data
tmpdir=/tmp
general_log_file=/tmp/logs/mysql.log
log_bin=/tmp/logs/mysql-bin.log
# DO NOT USE THIS NEXT LINE OR YOUR DB WILL BE LOCKED IN READ ONLY MODE
# innodb_force_recovery = 1


It's important to note that sysuser is actually the user who OWNS the directories on your system (ie. root or yourMacUserName), not to be confused with your mysql users. So, in my case, I would also need to make sure that the datadir, pid-file-dir, socket-dir, and log-dir are all accessible (via chown) by 'sysuser'.


now try starting the db via: sudo mysql.server start