Fixing Uninitialized Constant MysqlCompat::MysqlRes Error on Snow Leopard

by Rob Bazinet on November 25, 2009
Apple

Recently I ran into a problem on my MacBook Pro running Snow Leopard when trying to connect to a MySQL database.  The current version of the gem (2.8.1) installed fine but when trying to use it, I received the following error:

uninitialized constant MysqlCompat::MysqlRes

When trying to spin up a Rails application on my Mac.  I am running Snow Leopard and already had the MySQL gem installed.  A bit of searching around the web led to some information that this is an issue to do with the MySQL driver, in particular mysql-2.8.1.  The explanation came from a thread on StackOverflow.com:

As it turns out, that class should not exist; the error message is caused by a problem with the latest Mysql driver. mysql-2.8.1 looked for my libraries in a directory named with an extra level of ‘mysql’ at the end. For instance, my libraries (under MacOS X 10.5.8), are in /usr/local/mysql/lib, but the mysql.bundle library looks for the MySQL libraries at /usr/local/mysql/lib/mysql … which is wrong.

I tried some of the suggestions in the thread which suggested a straight install of the MySQL 2.7 gem but the result was the same.  It seems things are treated a bit differently on OS X 10.5.x and 10.6.x because of the 64-bit goodness we now have, but I was able to resolve the issue.  The first step was to uninstall my current MySQL gem:

sudo gem uninstall mysql

The command is a bit long but we basically want to install the version 2.7 of the MySQL gem and tell it where the MySQL main directory is located as well as where the configuration is located.  This command should be entered in a single line from a Terminal prompt (broken up here for display purposes):

export ARCHFLAGS="-arch i386 -arch x86_64" ;sudo gem install --no-rdoc --no-ri  -v=2.7 mysql -- --with-mysql-dir=/usr/local/mysql  --with-mysql-config=/usr/local/mysql/bin/mysql_config
Firing up the Rails application worked like a champ after the gem installed.  I would imagine there will be a fix for the MySQL gem 2.8.1 or maybe there is already a workaround I did not come across in my search.  MySQL is working Snow Leopard for my Rails applications, so I am happy.
 
Technorati Tags: ,,

Glad you liked it. Would you like to share?

Sharing this page …

Thanks! Close

Comments for this page are closed.

Showing 20 comments

Sort by   Subscribe by email   Subscribe by RSS

Trackbacks

Trackback URL 

Previous post:

Next post: