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: ,,
  • http://macapple.com.cn/fixing-uninitialized-constant-mysqlcompatmysqlres-error-on-snow/ Fixing Uninitialized Constant

    RE: Fixing Uninitialized Constant MysqlCompat::MysqlRes Error on Snow Leopard

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

  • http://macapple.com.cn/fixing-uninitialized-constant-mysqlcompatmysqlres-error-on-snow/ Fixing Uninitialized Constant MysqlCompat::MysqlRes Error on Snow … Mac Apple

    RE: Fixing Uninitialized Constant MysqlCompat::MysqlRes Error on Snow Leopard

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

  • http://rvm.beginrescueend.com/ Wayne Seguin

    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

  • http://rvm.beginrescueend.com/ Wayne Seguin

    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

  • CRC

    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

  • CRC

    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

  • http://comprar-imoveis.mude-se.com.br/comprarimoveis/ comprar imoveis

    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!

  • http://comprar-imoveis.mude-se.com.br/comprarimoveis/ comprar imoveis

    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!

  • http://www.drebarnes.com/ Andre Barnes

    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!

  • http://www.drebarnes.com Andre Barnes

    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!

  • http://maraby.org/ Matt Todd

    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).

  • http://maraby.org/ Matt Todd

    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).

  • http://www.accidentaltechnologist.com/ Rob Bazinet

    @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.

  • http://www.accidentaltechnologist.com/ Rob Bazinet

    @Andre – awesome, glad I could help.

  • http://www.accidentaltechnologist.com Rob Bazinet

    @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.

  • http://www.accidentaltechnologist.com Rob Bazinet

    @Andre – awesome, glad I could help.

  • AlFaisal ElDajani

    Cheers mate.. worked like a charm

  • AlFaisal ElDajani

    Cheers mate.. worked like a charm

  • http://www.brycecorkins.com/ Bryce Corkins

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

  • http://www.brycecorkins.com Bryce Corkins

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

  • http://oculosdesol.net.br/ oculos de sol

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

  • http://oculosdesol.net.br oculos de sol

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

  • http://railsdog.com/ Sean Schofield

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

  • http://railsdog.com Sean Schofield

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

  • Pepe

    man, thx a lot.
    did a great job for me

  • Pepe

    man, thx a lot.

    did a great job for me

  • ray

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

  • ray

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

  • http://activekita.blogspot.com/ Active

    I’ll try. Thank’s

  • http://activekita.blogspot.com Active

    I’ll try. Thank’s

  • http://lrdesign.com/ Evan Dorn / Logical Reality De

    Thank you! This finally solved my problem.
    Wonder why this didn’t happen on my other Snow Leopard machine…

  • http://lrdesign.com Evan Dorn / Logical Reality Design

    Thank you! This finally solved my problem.

    Wonder why this didn’t happen on my other Snow Leopard machine…

  • http://glenc.com/?p=4 glenc.com

    RE: Fixing Uninitialized Constant MysqlCompat::MysqlRes Error on Snow Leopard

    Pingback from glenc.com

  • http://glenc.com/?p=4 glenc.com

    RE: Fixing Uninitialized Constant MysqlCompat::MysqlRes Error on Snow Leopard

    Pingback from glenc.com

  • Rajesh

    Thanks a hundred, you have saved my day.

  • Rajesh

    Thanks a hundred, you have saved my day.

  • Jana

    Awesome, this was the only site that helped me tonight!!! Your rock!

  • Pingback: uninitialized constant MysqlCompat::MysqlRes()

  • http://www.dshan.me/blog DShan

    You’re my new best friend.

  • Pingback: Trevor Turk — Links for 5-17-11()