How to Install ruby mysql on Mac OS X 10.6 (Snow Leopard)
Do a quick google search for “ruby mysql mac” and you’ll find the first result:
How to install the MySQL/Ruby gem on Mac OS X Leopard
This article really helped me when I was using Mac OS X 10.5 and wanted to connect to MySQL with ruby. I just got a Macbook Pro with Mac OS X 10.6 (snow leopard) pre-installed and the method this article taught us no longer works. Do a simple test in irb and ruby will give you an error like:
>> Mysql.new('localhost', 'user', 'pass', 'db')
ArgumentError: wrong number of arguments (4 for 0)
from (irb):4:in `initialize'
from (irb):4:in `new'
from (irb):4
After trying a lot of ways, I finally got Ruby/MySQL working on my new Mac. The article mentioned above told us to install the x86 version of MySQL and set ARCHFLAGS=”-arch i386″. But on Mac OS X 10.6 (snow leopard), we should install x86_64 version for snow leopard (Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive) and set ARCHFLAGS=”-arch x86_64″. The complete command:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- \
--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include
I only tested this way to install ruby mysql on the newest Macbook Pro models with snow leopard pre-installed so not sure if it also works on old models that are upgraded to 10.6 snow leopard.
How to uninstall MySQL on Mac OS X? I’m using the method described in “Uninstalling MySQL on Mac OS X Leopard“. Yes again – this article is also for Leopard, but I used it on Mac OS X Snow Leopard with no problem.
July 9th, 2010 at 5:57 am
Thanks very much, that solved my problem as well.
September 21st, 2010 at 8:21 pm
Thank you – you saved me from much frustration.
I ran the first command with the proper architecture arguments and that did the trick.
Uninstalling MySQL is a different issue – this might be a bit confusing leaving that as a part of the article.
October 4th, 2010 at 12:22 pm
Thank you!
July 12th, 2011 at 4:07 pm
dont work for me … ;(
July 16th, 2011 at 9:20 am
If you’re using RVM you willl need to specify where the ruby headers are.
env ARCHFLAGS=”-arch x86_64″ gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config –with-ruby-include=/Users/craig/.rvm/src/ruby-1.9.2-p180/
July 24th, 2011 at 10:00 pm
Thanks. I had it installed but it was incredibly slow, for some reason replacing it with your gem install line, fixed it quickly.
Thanks again!
August 3rd, 2011 at 6:29 pm
I ran into new issues with an upgrade to os Lion.
This fixed it for me:
env ARCHFLAGS=”-arch x86_64″ gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config –with-ruby-include=/Users/craig/.rvm/src/ruby-1.9.2-p180/ –with-mysql-dir=/usr/local/mysql –with-mysql-lib=/usr/local/mysql/lib –with-mysql-include=/usr/local/mysql/include
March 23rd, 2012 at 9:29 am
Thank you. That saved a lot of time for me.