Fixing Uninitialized Constant MysqlCompat::MysqlRes Error on Snow Leopard

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: ,,

Feedback

 avatar
#1
Wayne Seguin
11.26.2009 @ 7:04 AM

Also, If anyone uses rvm and encounters issues installing mysql there is a growing exposition of the issues on the website rvm.beginrescueend.com/.../mysql

Thanks,

~Wayne

 avatar
#2
CRC
12.05.2009 @ 4:51 PM

This approach has moved me beyond the uninitialized constant MysqlCompat::MysqlRes problem, but now I'm getting: Failed to load /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle

 avatar
#3
comprar imoveis
12.17.2009 @ 1:52 PM

I'll try that!

Rails is very powerfull, but some times trick. That kind of post helps to spread rails to some dummy users like me.

Thanks!

 avatar
#4
Andre Barnes
12.28.2009 @ 1:15 PM

Big Thank you dude!!!! This method works!!! I have looked for hours to find a solution and yours is the first to work!!! THANK YOU!

 avatar
#5
Matt Todd
12.28.2009 @ 6:51 PM

Aman Gupta enlightened me to this very important fact: twitter.com/.../7139387431

Summary: you may need to reinstall Ruby to the latest version (darwin10* build).

rbazinet avatar
#6
Rob Bazinet
12.29.2009 @ 9:26 AM

@Matt - Thanks, good to know. I had applied this method to MySQL for both the Apple installation of Ruby on Snow Leopard and reapplied to the latest version when I built my own Ruby (1.8.7) and it all worked great.

rbazinet avatar
#7
Rob Bazinet
12.29.2009 @ 9:26 AM

@Andre - awesome, glad I could help.

 avatar
#8
AlFaisal ElDajani
01.01.2010 @ 6:00 PM

Cheers mate.. worked like a charm

 avatar
#9
Bryce Corkins
01.06.2010 @ 3:41 PM

This worked perfectly... and saved me a lot of frustration. Thank you.

 avatar
#10
oculos de sol
01.12.2010 @ 2:43 PM

How lucky I am to find your solution. It works!!!

 avatar
#11
Sean Schofield
01.31.2010 @ 7:10 PM

Thanks. I found a lot of different suggestions out there but this was the exact combination of command line arguments that was needed.

 avatar
#12
Pepe
02.19.2010 @ 6:05 PM

man, thx a lot.

did a great job for me

 avatar
#13
ray
03.08.2010 @ 10:21 AM

thanks... your solution worked great, and saved a lot of headbanging.

» Trackbacks & Pingbacks

  1. Pingback from Fixing Uninitialized Constant MysqlCompat::MysqlRes Error on Snow … Mac Apple

Trackback link for this post:
http://accidentaltechnologist.com/trackback.ashx?id=438

Leave a Comment