Do a quick google search for “ruby mysql mac” and you’ll find the first result:
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.