sweller blog

Start-ups, the web, technology and being a dad.

0 notes

OS X, Snow Leopard, Ruby & the mysql gem

Ok, so managing Ruby development under Mac is seemingly in its infancy, even though 90% of everyone I know who develops in Ruby and Rails does so on a Mac.

If anyone else out there is finding issues with getting the mysql gem to work on Snow Leopard, do not install MYSQL from the dmg. You’ll be asking for trouble. Your best bet is to use the version that is available through MacPorts. I have not had the time to debug *why* the dmg fails to work with the 2.8.1 mysql gem, but I’ve been able to get it to work by simply installing the 64-bit mysql via MacPorts and build the gem using a 64-bit ARCH type.

Thanks to Peter Kovacs for suggesting I try the following sequence of commands.

First, uninstall mysql and then the mysql gem, if they are already installed.

Then run:

  • sudo port install mysql5
  • sudo port install mysql5-server
  • sudo vi /opt/local/etc/mysql5/my.cnf
    [mysqld_safe]
    socket = /tmp/mysql.sock

    [mysql]
    socket = /tmp/mysql.sock

    [mysqladmin]
    socket = /tmp/mysql.sock
  • sudo -u _mysql mysql_install_db5
  • sudo port load mysql5-server
  • mysql5 -u root -e “CREATE USER ‘[your username]’@’localhost’”
  • mysql5 -u root -e “GRANT ALL ON *.* TO ‘[your username]’@’localhost’”
  • sudo ln -s /opt/local/bin/mysql5 /opt/local/bin/mysql
  • sudo ln -s /opt/local/bin/mysqladmin5 /opt/local/bin/mysqladmin
  • sudo env ARCHFLAGS=”-arch x86_64” gem install mysql — —with-mysql-config=/opt/local/bin/mysql_config5

Please note you need to replace “[your username]” with the your username.