Installing MySQL 5.5 on OS X 10.6 (Snow Leopard) and Rails 3

Rick Wargo

I was successfully able to install MySQL 5.5 on OS X 10.6 according to the following steps.

Download MySQL Community Server 5.5.8 for Mac OS X. I chose to download Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive. The DMG archive is nice as it has a startup package that installs a MySQL control panel (although it dosn’t work from the start without tweaking).

Open the DMG archive and execute the mysql-5.5.8-osx10.6-x86_64.pkg. I had no issues with installation although the ReadMe.txt file suggests that problems may occur.

After successful installation, execute the MySQLStartupItem.pkg. This will install the MySQL Startup startup items. This should complete successfully.

Next, install the MySQL preferences pane by double-clicking the MySQL.prefPane item in the mounted drive. This will install the MySQL preferences item, although MySQL cannot yet be started through it. First, the mysql.server file must be edited by hand to specify the location of the base directory.

At a terminal, cd to /usr/local/mysql/support-files and edit mysql.server (with root privileges, using sudo). Around line 46 locate the lines that read:

basedir=
datadir=

and change them to read

basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

Save the file. MySQL can now be started from the preferences pane. Without it, you will see a message in the Console that reads:

mysql.server: line 256: my_print_defaults: command not found

To enable rails 3 to use mysql, install the mysql2 gem. Next, you’ll need to set the DYLD_LIBRARY_PATH to include the MySQL library directory. To do this, edit your ~/.bash_profile and include the following:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

The rails server will now successfully start. Without the inclusion of the directory in the DYLD_LIBRARY_PATH, a message about not finding the library would appear and the server would abort.

The error message, from the mysql2 gem, states (in part):

Library not loaded: libmysqlclient.16.dylib (LoadError)

Upon reboot, MySQL will fail to start with a dialog stating:

Insecure Startup Item disabled.
“/Library/StartupItems/MySQLCOM” has not been started because it does not have the proper security settings.

The group permissions need to be changed to wheel on the MySQL directory by executing the following command in the terminal:

sudo chown -R root:wheel /Library/StartupItems/MySQLCOM

This will prevents the startup error dialog. Finally, ensure the Automatically Start MySQL Server on Startup is checked in the MySQL preferences window.

Good luck!

Share and Enjoy:
  • Facebook
  • Twitter
  • LinkedIn
  • StumbleUpon
  • del.icio.us
  • Google Buzz
  • Yahoo! Buzz
  • Digg
  • email

21 Responses to “Installing MySQL 5.5 on OS X 10.6 (Snow Leopard) and Rails 3”

  1. Rob Munroe Says:

    MySQL? I shy away from Oracle products. ;) PostgreSQL all the way!

  2. thankyou Says:

    oh,Thank you very much!!! You help me!

  3. Mike Says:

    Thanks, worked out for me!!

  4. Andy Says:

    :) cheers for this! Worked like a charm.

  5. Derek Says:

    Thank you for the MySQL tidbit. Setting the basedir and datadir were the missing pieces I needed.

  6. Salvoemme Says:

    Sei il numero 1 – You are number one!

  7. David Says:

    I’ve this:

    sudo chown -R root:wheel /Library/StartupItems/MySQLCOM

    … and it didn’t work. Do you have another suggestion?

    Thanks!

  8. Jeff Says:

    thanks for taking the time to publish this… worked like a champ.

  9. Rick Wargo Says:

    What didn’t work, David? Was there an error message? Have you completed the other steps?

  10. Andrew Says:

    Hello, thanks for the article!

    I have followed all steps except those involving Rails. I currently have php5 installed and working properly.
    MySql does not start up when I use preferences pane button.
    To start in terminal I enter the following lines:

    shell> cd /usr/local/mysql
    shell> sudo ./bin/mysqld_safe

    And I receive the following errors:

    110329 00:38:56 mysqld_safe Logging to ‘/usr/local/mysql-5.5.10-osx10.6-x86/data/Andrew-Jordan-Millers-MacBook-Pro.local.err’.
    110329 00:38:56 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql-5.5.10-osx10.6-x86/data
    110329 00:38:58 mysqld_safe mysqld from pid file /usr/local/mysql-5.5.10-osx10.6-x86/data/Andrew-Jordan-Millers-MacBook-Pro.local.pid ended

    I have read many articles and browsed many forums with little success. From my research I believe the error involves a missing .sock file in /tmp directory.
    Any help is much appreciated!
    -A

  11. Rick Wargo Says:

    Andrew, did you check the local.err file? It doesn’t appear that it starts successfully from the command line.

  12. Andrew Says:

    Thank you, Rick. I have just checked the local.err and here are the contents:

    10329 00:34:02 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
    110329 0:34:02 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
    110329 0:34:04 [Note] Plugin ‘FEDERATED’ is disabled.
    110329 0:34:04 InnoDB: The InnoDB memory heap is disabled
    110329 0:34:04 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    110329 0:34:04 InnoDB: Compressed tables use zlib 1.2.3
    110329 0:34:05 InnoDB: Initializing buffer pool, size = 128.0M
    110329 0:34:05 InnoDB: Completed initialization of buffer pool
    InnoDB: The first specified data file ./ibdata1 did not exist:
    InnoDB: a new database to be created!
    110329 0:34:06 InnoDB: Setting file ./ibdata1 size to 10 MB
    InnoDB: Database physically writes the file full: wait…
    110329 0:34:07 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
    InnoDB: Setting log file ./ib_logfile0 size to 5 MB
    InnoDB: Database physically writes the file full: wait…
    110329 0:34:08 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
    InnoDB: Setting log file ./ib_logfile1 size to 5 MB
    InnoDB: Database physically writes the file full: wait…
    InnoDB: Doublewrite buffer not found: creating new
    InnoDB: Doublewrite buffer created
    InnoDB: 127 rollback segment(s) active.
    InnoDB: Creating foreign key constraint system tables
    InnoDB: Foreign key constraint system tables created
    110329 0:34:10 InnoDB: Waiting for the background threads to start
    110329 0:34:11 InnoDB: 1.1.5 started; log sequence number 0
    110329 0:34:11 [ERROR] Can’t start server : Bind on unix socket: Permission denied
    110329 0:34:11 [ERROR] Do you already have another mysqld server running on socket: /temp/mysql.sock ?
    110329 0:34:11 [ERROR] Aborting

    110329 0:34:11 InnoDB: Starting shutdown…
    110329 0:34:12 InnoDB: Shutdown completed; log sequence number 1595675
    110329 0:34:12 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

    110329 00:34:12 mysqld_safe mysqld from pid file /usr/local/mysql/data/Andrew-Jordan-Millers-MacBook-Pro.local.pid ended
    110329 00:34:24 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
    110329 0:34:24 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
    110329 0:34:24 [Note] Plugin ‘FEDERATED’ is disabled.
    110329 0:34:24 InnoDB: The InnoDB memory heap is disabled
    110329 0:34:24 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    110329 0:34:24 InnoDB: Compressed tables use zlib 1.2.3
    110329 0:34:24 InnoDB: Initializing buffer pool, size = 128.0M
    110329 0:34:24 InnoDB: Completed initialization of buffer pool
    110329 0:34:24 InnoDB: highest supported file format is Barracuda.
    110329 0:34:24 InnoDB: Waiting for the background threads to start
    110329 0:34:25 InnoDB: 1.1.5 started; log sequence number 1595675
    110329 0:34:26 [ERROR] Can’t start server : Bind on unix socket: Permission denied
    110329 0:34:26 [ERROR] Do you already have another mysqld server running on socket: /temp/mysql.sock ?
    110329 0:34:26 [ERROR] Aborting

    110329 0:34:26 InnoDB: Starting shutdown…
    110329 0:34:26 InnoDB: Shutdown completed; log sequence number 1595675
    110329 0:34:26 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

    110329 00:34:26 mysqld_safe mysqld from pid file /usr/local/mysql/data/Andrew-Jordan-Millers-MacBook-Pro.local.pid ended
    110329 00:37:05 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
    110329 0:37:05 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
    110329 0:37:05 [Note] Plugin ‘FEDERATED’ is disabled.
    110329 0:37:05 InnoDB: The InnoDB memory heap is disabled
    110329 0:37:05 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    110329 0:37:05 InnoDB: Compressed tables use zlib 1.2.3
    110329 0:37:05 InnoDB: Initializing buffer pool, size = 128.0M
    110329 0:37:05 InnoDB: Completed initialization of buffer pool
    110329 0:37:05 InnoDB: highest supported file format is Barracuda.
    110329 0:37:05 InnoDB: Waiting for the background threads to start
    110329 0:37:06 InnoDB: 1.1.5 started; log sequence number 1595675
    110329 0:37:07 [ERROR] Can’t start server : Bind on unix socket: Permission denied
    110329 0:37:07 [ERROR] Do you already have another mysqld server running on socket: /temp/mysql.sock ?
    110329 0:37:07 [ERROR] Aborting

    110329 0:37:07 InnoDB: Starting shutdown…
    110329 0:37:07 InnoDB: Shutdown completed; log sequence number 1595675
    110329 0:37:07 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

    110329 00:37:07 mysqld_safe mysqld from pid file /usr/local/mysql/data/Andrew-Jordan-Millers-MacBook-Pro.local.pid ended
    110329 00:37:13 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
    110329 0:37:14 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
    110329 0:37:14 [Note] Plugin ‘FEDERATED’ is disabled.
    110329 0:37:14 InnoDB: The InnoDB memory heap is disabled

    ——————–

    I have checked my /temp directory and it is empty. MySql was running properly at one point a couple weeks ago on my machine. Things went awry and I have since tried several times to uninstall and reinstall while following various instructions.

    best,
    A

  13. Rick Wargo Says:

    Andrew, the ERROR lines indicate a problem you referenced earlier – about not being able to write to the socket. My guess is that you already have mysqld running. Check with:

    ps -ef|grep -i mysql

    If you don’t see mysql, ensure that the ownership of the files are correct. Good luck.

  14. Joel Says:

    Hey, I went through the same process and it still isn’t working.
    Looked for local.err, not sure where to find it.

    Checking my mysqld returned:
    0 482 1 0 0:00.01 ?? 0:00.02 /bin/sh /usr/local/mysql/bin/mysqld_safe –datadir=/usr/local/mysql/data –pid-file=/usr/local/mysql/data/localhost.pid
    74 554 482 0 0:00.05 ?? 0:00.15 /usr/local/mysql/bin/mysqld –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data –plugin-dir=/usr/local/mysql/lib/plugin –user=mysql –log-error=/usr/local/mysql/data/localhost.err –pid-file=/usr/local/mysql/data/localhost.pid
    501 692 416 0 0:00.00 ttys000 0:00.00 grep -i mysql

    Honestly, I’m not sure what any of this means :)
    But when I enter “rails server” on my app directory, I get a whole list of errors related to the mysql2, bundler and railties.
    LoadError, image not found, etc.

    This after I’ve followed these steps to the letter. Any suggestions?

    Thanks!

  15. Rick Wargo Says:

    Joel, it appears that MySQL is running and most likely listening on localhost. The problems may be related to something else.

  16. Jeff Says:

    I’m launching rails from XCode, so its not reading my environment variables. I attempted to add an environment.plist file to the ~.MacOSX directory as recommended at Apple, but to no avail. Any suggestions?

  17. Fritz Says:

    :) THANK YOU!!!!! Rick, you literally saved me hours maybe days trying to figured this out. Have a great day and thanks again!

  18. Jeff Says:

    Well, the best solution for my problem is to stop using XCode. Its not exactly the best rails IDE out there. I switched to RubyMine and it seems to launch with no problem.

  19. Simetx Says:

    Thank you Rick. I looking for the solution to solve my problem. It works fine.

  20. James Says:

    Thank you!! The .bash_profile addition fixed my problem! Didn’t need to adjust permissions though, guess I got lucky. You’ve cured me of quite a bit of frustration! :-D

  21. MySQL - Management - Techniques | Pearltrees Says:

    [...] Installing MySQL 5.5 on OS X 10.6 (Snow Leopard) and Rails 3 « epicblog I was successfully able to install MySQL 5.5 on OS X 10.6 according to the following steps. Download MySQL Community Server 5.5.8 for Mac OS X. I chose to download Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive . The DMG archive is nice as it has a startup package that installs a MySQL control panel (although it dosn’t work from the start without tweaking). Open the DMG archive and execute the mysql-5.5.8-osx10.6-x86_64.pkg. I had no issues with installation although the ReadMe.txt file suggests that problems may occur. [...]

stop spam with honeypot!