views:

3374

answers:

9

Hi All

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 http://stackoverflow.com/questions/1332207/uninitialized-constant-mysqlcompatmysqlres-using-mms2r-gem but it doesn't seem applicable for my version.

+1  A: 

I have applied the instructions of hivelogic post but with version 5.1.41 of MySQL. And for the gem installation I did 2 things:

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

And things worked great for me.

khelll
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
emson
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.
khelll
A: 

Thanks khell - but I'm still getting this problem.

It's really baffling. This is a synopsis of what I've done so far to fix it:

  1. Uninstalled MySQL 5.1.41.1, using make uninstall as it suggests in the hivelogic post.
  2. Deleted all remaining files from the /usr/local/mysql directory
  3. Reinstalled MySQL 5.1.39
  4. Tested the database, all works fine, I can use it with Django.
  5. Uninstalled the ruby mysql gem
  6. Reinstalled the ruby mysql gem (2.8.1) (also tried 2.7 - no joy either).

These are the various commands I tried. I uninstalled and before trying each one:

    sudo gem install --no-rdoc --no-ri mysql -v 2.7 -- --with-mysql-dir=/usr/local --with-mysql-config=/usr/local/mysql/bin/mysql_config

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

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

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

This is what happens when I try and use the db commands in rake:

    computer01:trunk bently$ rake db:create
    (in /Users/bently/devel/rails/project/trunk)
    Couldn't create database for {"adapter"=>"mysql", "username"=>"root", "database"=>"project_dev", "host"=>"localhost", "password"=>nil, "socket"=>"/tmp/mysql.sock"}, charset: utf8, collation: utf8_general_ci (if you set the charset manually, make sure you have a matching collation)
    computer01:trunk bently$ 

But when I do a rake db:collation I get the usual error:

    computer01:trunk bently$ rake db:collation
    (in /Users/bently/devel/rails/project/trunk)
    rake aborted!
    uninitialized constant MysqlCompat::MysqlRes

    (See full trace by running task with --trace)
    computer01:trunk bently$

Is there any way I can see what is happening, any logging or verbose in information?

Anyone got any ideas? I'm really struggling to figure this out.

Many thanks

emson
+1  A: 

Same problem. I watch a fantastic screen cast by Ryan Bates, get all excited about Rails again, then have to wrestle with issue like this. It drives me nuts.

Sorry to be negative.

Jon
+1  A: 

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!

rixter
+6  A: 

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 (http://pivotallabs.com/users/chad/blog/articles/407-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. Hope it works for you to.

B

emson
I found out that just recompile step #2 solve my problem, Thank you for you post.
Jirapong
A: 

Hi All- I worked pretty hard getting this resolved for the last day and I finally figured it out. I'm running snow leopard and did a fresh rails and mysql install. The only way I got this to work was to install the 64bit version of mysql from the dmg (not macports) and restart my machine in 64 bit mode by holding the "6" and "4" keys down while booting. Then I installed the gem, set my DB host to local and it worked like a champ.

jonathan simon
+3  A: 

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.

Sudhir
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.
abeger
+1  A: 

After racking my head with the problem, I too found that the problem had to do with multiple binaries of the same mysql gem version installed. The following fixed it for me.

gem uninstall mysql
Select gem to uninstall:
 1. mysql-2.8.1
 2. mysql-2.8.1
 3. All versions
> 3

Successfully uninstalled mysql-2.8.1
Successfully uninstalled mysql-2.8.1

Next, I recompiled the mysql gem from source on my Snow Leopard machine, and all was swell with the world.

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql-5.1.46-osx10.6-x86_64/bin/mysql_config
Manu R
A: 

Several problems were related to obsolete or multiple conflicting binaries of rubies and gems. I have myself had the problem to "transparently" compile the mysql gem with the system ruby, while trying to get my code run with ruby 1.9. After figuring out the problem thanks to this thread, everything went smoothly.

To avoid these issues and for the records, the RVM toolkit may be very handy: http://rvm.beginrescueend.com. It helps in properly managing several ruby versions, and it cleverly manages gems for all versions without keeping a copy for each version.

It seems that the use of RVM can help in avoiding several of the issues in this thread.

Eric Platon