Installing MySQL via MacPorts on Snow Leopard for Ruby Development

Tuesday, September 1, 2009

There are a number of tutorials floating around that explain how to install MySQL 5 on Snow Leopard. They all recommend the x86_64 universal binary supplied by MySQL. If you’d like to install MySQL via MacPorts (MySQL5 is certified compatible!), here are the steps:

  1. Install MySQL with developer libraries:

    sudo port install mysql5-devel

  2. Create the required databases:

    sudo /opt/local/lib/mysql5/bin/mysql_install_db –user=mysql

    If you get permissions errors, run (warning: don’t do this in production!):

    sudo chmod -Rf 777 /opt/local/var/db/mysql5

    and repeat.

  3. Set your mysql password:

    /opt/local/lib/mysql5/bin/mysqladmin -u mysql password ‘your-password-here’

Now, for the MySQL gem:

  1. One-line install with MacPorts config path:

    sudo gem install mysql — –with-mysql-config=/opt/local/bin/mysql_config5

    or, if you want to use version 2.7 (instead of the latest 2.8.1):

    sudo gem install mysql –version 2.7 — –with-mysql-config=/opt/local/bin/mysql_config5

You’re ready to roll. To start your MySQL daemon, run:

sudo /opt/local/lib/mysql5/bin/mysqld_safe &

Now you go:

3 comments:

  1. Tuesday, November 17, 2009theo says:

    hi Robby, thx for tutorial – it really helps me, but u got a type on first lines

    sudo port install mSyql5-devel

  2. Tuesday, November 17, 2009Robby Grossman says:

    Thanks, theo… and fixed!

    –Robby

  3. Thursday, August 19, 2010Install a Rails enviroment on Snow Leopard with Macports, Mysql and ModRails Passenger (updated) | Ruby, Rails, OSX and Linux fun says:

    [...] http://rob.by/2009/installing-mysql-via-macports-on-snow-leopard-for-ruby-development/ [...]