Fixing the startup and PrefPane bugs with MySQL on Mac OS X 10.6 Snow Leopard

There is a bug with MySQL on Snow Leopard. In fairness, the bug appears to be 100% the fault of MySQL, not Apple. Specifically, the PreferencePane does not actually allow startup and shutdown of the MySQL server process, and the Automatically Start MySQL Server on Startup checkbox does not work either. In addition, an annoying message about incorrect permissions occurs at startup.

The bug occurs with the standard download from http://www.mysql.com/downloads/mysql/. As of this writing the Generally Available MySQL Community Server is at version 5.5.8, and I used the 64 bit, DMG archive. This fix has been shown to correct issues on MacOS X 10.6.5 Server and 10.6.6 Client. Since the bug is the fault of MySQL and not Apple, I expect it will work anywhere it is needed. This bug may have been fixed since this posting (maybe even before), or a new bug may have been introduced, so your mileage may vary.

The bug did not exist in version 5.1.30 of MySQL. When/where/why it was introduced is an absolute mystery to me. It really seems inexcusable, and although the good folks at MySQL (I guess it's managed by Oracle now) have known about this for more than 6 months and the severity level has been raised to severe, it remains unfixed as of January 21, 2011.

My thanks to the authors on these sites who provided the answer. Hopefully I have taken this a step further and made it more clear.
http://forums.mysql.com/read.php?11,400354,400491#msg-400491
http://bugs.mysql.com/bug.php?id=55530
http://bugs.mysql.com/bug.php?id=53232

Step 1 - fix the file at /usr/local/mysql/support-files/mysql.server . This can be opened with pico, nano, vi, TextWrangler or whichever text editor you prefer. You will need administrator permissions. To open with pico, type this at your Terminal prompt:

For example:
[icebook2:~] jwb% sudo pico /usr/local/mysql/support-files/mysql.server

You may view the few changes needed in living color and in full context in this PDF file.

You may view the few changes in partial context in the following table.

Original Fixed Fixed (with comments)
# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
  basedir=.
  bindir=./bin
  if test -z "$datadir"
  then
    datadir=/usr/local/mysql/data
  fi
# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
  basedir=/usr/local/mysql
  bindir=./bin
  if test -z "$datadir"
  then
    datadir=/usr/local/mysql/data
  fi
# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
# bug fix
#
  basedir=.
  basedir=/usr/local/mysql
  bindir=./bin
  if test -z "$datadir"
  then
    datadir=/usr/local/mysql/data
  fi
#
# Set pid file if not given
#
if test -z "$mysqld_pid_file_path"
then
  mysqld_pid_file_path=$datadir/`hostname`.pid
else
  case "$mysqld_pid_file_path" in
    /* ) ;;
    * ) mysqld_pid_file_path="$datadir/$mysqld_pid_file_path" ;;
  esac
fi
#
# Set pid file if not given
#
if test -z "$mysqld_pid_file_path"
then
  mysqld_pid_file_path=$datadir/`/bin/hostname`.pid
else
  case "$mysqld_pid_file_path" in
    /* ) ;;
    * ) mysqld_pid_file_path="$datadir/$mysqld_pid_file_path" ;;
  esac
fi
#
# Set pid file if not given
#
if test -z "$mysqld_pid_file_path"
then
# bug fix
#
  mysqld_pid_file_path=$datadir/`hostname`.pid
mysqld_pid_file_path=$datadir/`/bin/hostname`.pid
else
  case "$mysqld_pid_file_path" in
    /* ) ;;
    * ) mysqld_pid_file_path="$datadir/$mysqld_pid_file_path" ;;
  esac
fi


That should fix the PrefPane issue.

Step 2 - To fix the startup issue, execute this line in the Terminal (you will need admin permissions):
For example:
[icebook2:~] jwb% sudo chown -R root:wheel /Library/StartupItems/MySQLCOM
Well that was easy!



An alternative solution is to use the following Applescript.


Insert your password in the correct spot and save as an application. Be sure to check the "Run Only" checkbox (to protect your password from prying eyes) and do not check the "Startup Screen" and "Stay Open" checkbox.


Set this application as a Login Item by clicking on the Accounts icon of System Preferences. It will run at login (NOT startup - there is a difference) and get MySQL going. This is not a secure option for a production server, but should suffice for hobbyists running MySQL on a local machine.





 © 1997-2022 Jeffrey W Baumann dba LinkedResources. All Rights Reserved. Last Updated December 28, 2021.