Hello, I’m a web craftsman with a passion for the modern web. I build web applications and play with social services and communities.

August 5, 2010 at 5:12 pm

When running rake tasks (that are related to the database) in Rails apps I ran into the following error a couple of times on different OS X Snow Leopard machines:

uninitialized constant MysqlCompat::MysqlRes

The mysql gem is installed but got compiled for a wrong architecture for some reason. I’m not 100% sure when this happens but if you run into the problem uninstall the mysql gem

$ sudo gem uninstall mysql

and reinstall it with this flag

$ sudo env ARCHFLAGS="-arch x86_64" gem install mysql

if you are using rvm you can skip the “sudo” on all commands.


December 11, 2009 at 2:04 am

I spend the last couple of hours trying to get Ruby on Rails (2.3.5) to work with MySQL on Mac OS X 10.6 Snow Leopard. So far I have been using SQLite for Rails Development but a current project requires some MySQL specific functions. I didn’t expect things to be so rough but now everything works and I am quite happy. So happy that I decided to write it down and share it with the world.

First: What was the problem?

Since I’m coming from PHP/MySQL development I had XAMPP already installed on my system and I was hoping to use the same XAMPP-bundled MySQL Server I have been using for all my PHP projects for rails projects too. Forget it! Don’t waste your time here. You may get it to work somehow but you will run into trouble at some point since XAMPP’s MySQL is compiled in 32bit and Ruby on Snow Leopard in 64bit. So basically as soon as you have a Mac with a Core 2 Duo (or any other 64bit processor) and running 10.6 Snow Leopard you have to install a 64bit version of MySQL.

So the problem you will run into (or already ran in and that’s why you are here right now) while trying to install the mysql gem with sudo install mysql looks like this:

Building native extensions.  This could take a while…
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lsocket… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lnsl… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lmygcc… no
checking for mysql_query() in -lmysqlclient… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

and some more I won’t bore you with.

So here comes the solution:

1. Download MySQL 5.4 beta for Mac OS X 10.5 as x86_64 version from the official MySQL website

2. Open up the downloaded .dmg and run the mysql-5.4.x-…x86_64.pkg installer, followed by the MySQLStartupItem.pkg Installer. After that you install the MySQL.prefPane which allows you to start and stop the MySQL Server comfortably from the System Preferences (for some reason the prefPane is still in 32bit but that won’t bother us now).

3. Go into terminal and install the mysqlplus gem:

sudo gem install mysqlplus

4. That’s it!

It seems a bit crazy that I spend hours figuring that out but basically the key to success is mysqlplus here. I tried all kinds of combinations with the official MySQL 5.1/5.4, XAMPP’s MySQL, MacPorts MySQL and the standart mysql gem but none worked. Sometimes I got the mysql gem to compile and install but then rails still couldn’t connect to the database… However, now it works and I’m glad things can go on!