Problem installing mysql gem on Snow Leopard: uninitialized constant MysqlCompat::MysqlRes

11,879

Solution 1

OK, I've finally solved this problem.

The reason this was occurring was that I had two versions of Ruby installed.

  1. I had compiled and installed my own version of Ruby following the HiveLogic guidelines, pre my installation of Snow Leopard.
  2. I then upgraded to Snow Leopard (which has it's own version of Ruby)

These two versions conflicted and meant that when ever I tried to install the the MySQL gem with the correct ARCHFLAGS the system thought I was using a different version of Ruby.

The fix was simple enough:

  1. Remove the HiveLogic version of Ruby (https://content.pivotal.io/blog/removing-old-ruby-source-installation-after-a-leopard-upgrade)
  2. Recompile the MySQL gem with the correct ARCHFLAGS:

    sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Once I had done this everything worked fine.

Solution 2

Basically the problem is the the dynamic library libmysqlclient can't be found. The above solutions will work, but you need to reapply them any time you rebuild the gem, or when you install a new version of MySQL.

An alternative approach is to add the MySQL directory containing the library to your dynamic load path. Putting the following in my .bashrc file solved the problem:

export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

Solution 3

After wrestling with this problem for several days I finally got it nailed. 2 things that I have done that made it work:

  1. sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
  2. export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

I'm a bit surprised that #2 was only mentioned by Steven Chanin.

I'm on Snow Leopard, and have only 1 MySQL (x86_64) 5.5, and 1 ruby (prepackaged with Snow Leopard) installed.

Solution 4

Well, I am a newbie. After struggling for a while and since none of the above worked for me, I figured the problem was due to my "mysql" being a 64-bit installation while ruby was 32-bit. Check with these commands

file `which mysql`
file `which ruby`

Both should match Mach-O 64-bit executable x86_64 or Mach-O 64-bit executable i386. I installed a 32-bit mysql, reinstalled ruby from source and rails and things have been working flawlessly since. I am on Leopard btw.

Solution 5

Same problem here as well; have been wrestling with this off and on for over two weeks!

I'm no ROR expert, but from other more knowledgeable people who found a solution, the problem seems to point the Ruby Gem for mysql which, apparently, incorrectly installs itself on the Mac.

I will continue to investigate at the Ruby Forge site, and see if any Ruby Gem gurus can correct this horrible bug....I need my Rails working! Time is money!

So I reported this bug over at the RubyForge Mysql developers bug tracking page.

I sure hope they can help, as this is crippling my current project.

And if anyone else can support my bug report over there, perhaps it will get more attention; please chime in!

Share:
11,879
emson
Author by

emson

Updated on June 03, 2022

Comments

  • emson
    emson almost 2 years

    I've got a problem trying to install the Ruby mysql gem driver.

    I recently upgraded to Snow Leopard and did the Hivelogic manual install of MySQL. This all seems to work fine as I can access mysql from the command line and make changes to the database.

    My problem is that if I now use

    rake db:migrate 
    

    I get:

    rake aborted!
    uninitialized constant MysqlCompat::MysqlRes
    
    (See full trace by running task with --trace)
    

    Now it appears that my mysql gem isn't working correctly as I can access MySQL fine from Python using the Python driver (which I compiled to). I therefore tried to rebuild the gem using the following command from this site: http://techliberty.blogspot.com/, (incidentally I am using a recent Intel MacBook Pro):

      sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
    

    This compiles although I get No definition for the documentation:

      Building native extensions.  This could take a while...
      Successfully installed mysql-2.8.1
      1 gem installed
      Installing ri documentation for mysql-2.8.1...
    
      No definition for next_result
    
      No definition for field_name
      ...
    

    I'm a little stumped as my mysql_config is located in the correct place:

     /usr/local/mysql/bin/mysql_config
    

    And I have removed all other instances of the mysql gem, from my system.

    Any suggestions would be greatly appreciated. Many thanks.

    PS I saw this previous post uninitialized constant MysqlCompat::MysqlRes (using mms2r gem) but it doesn't seem applicable for my version.

  • emson
    emson over 14 years
    Thanks khell - yeah this is weird. I still have the same problem for some reason my system just does like it. I tried a rake db:drop and get: mysystem$ rake db:drop (in /Users/username/devel/rails/myproj/trunk) Couldn't drop myproj : #<NameError: uninitialized constant MysqlCompat::MysqlRes> Any other ideas? Thank
  • khelll
    khelll over 14 years
    did u try with version 5.1.41? also before that make sure you delete everything on /usr/local/mysql not to mix the build file.
  • Jirapong
    Jirapong about 14 years
    I found out that just recompile step #2 solve my problem, Thank you for you post.
  • abeger
    abeger almost 14 years
    Bless you and all that you stand for. I've been banging my head against this problem all afternoon and you finally solved it for me. I wish I could give more than just one upvote.
  • PowerKiKi
    PowerKiKi over 13 years
    also recompiled with given command and working fine. Thank you.
  • harm
    harm about 13 years
    Could you explain this with absolute paths?
  • andrewdotnich
    andrewdotnich over 12 years
    You are a prince among men! Thanks Steven!