简体   繁体   中英

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

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.

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"

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.

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.

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.

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.

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!

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

This can be a Mysql version problem. You should install the most stable version (MYSQL 5.1). See my blog post : http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/

If you're using MySQL 5.5, these are the steps that made it work for us:

Command to install mysql-2.8.1:

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

Command to make mysql-2.8.1 work with mysql 5.5:

sudo ln -s ../mysql/lib/libmysqlclient.16.dylib libmysqlclient.16.dylib

Hope that helps!

There is a chance that you followed the above instructions but forgot to kill the server before reinstalling Mysql. This will not make the error message go away. This happened to me.

After trying out all the different options here, I tried the following:

ps aux | grep 'mysql'

kill [pid_number_for_mysql]

Basically, kill the server.. the hard way. Then, restart the server.

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.

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.

In case someone is using rvm with ruby 1.8.7 and mysql x86 (32 bits version) and have this issue. You will find this link helpful: http://rvm.beginrescueend.com/integration/databases/ . You will need to install mysql in x86_64 version and then install the mysql gem with the archflags set to x86_64. The reason is that even you try to install the gem as x86 to match your mysql x86. However the ruby version is in 64 bits. So you really need to have all three match: Ruby, mysql and mysql gem. So the easier way is to have all of them in 64 bits.

Very quick fix for me.

This problem popped up on me again this week on a development machine I'd not used for sometime. As per Step 2 of emson's initial response, it only required a recompiling of 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

I had this, or at least a similar, issue (Hivelogic was not involved and it was not an upgrade, but rather a new system). I agree that it is probably a 64 bit issue. I have a link for you, that after all the other head and butt scratching I did, finally saved my ass (and brain).

[http://forums.mysql.com/read.php?116,359591,359591]

Best of luck getting past this configuration BS and on to some coding.

After searching for a long time on solving this particular problem, and trying out all of the above options (and the options on many other sites) without luck, I removed my mysql-5.5 install and installed mysql-5.1. All of a sudden, and with a bit of the above help for compiling 64 bit versions, I finally managed to install a working mysql gem.

So, if you're running into this problem and are running mysql 5.5, try degrading to mysql 5.1.

I had the same issue. I had installed mysql (in my case, 5.1.48 64-bit for Snow Leopard) in /usr/local/mysql/current/, not in /usr/local/mysql. However, the mysql client shard library (libmysqlclient.16.dylib) had a path of /usr/local/mysql/lib/libmysqlclient.16.dylib embedded in it.

After several abortive attempts to fix this using install_name_tool, what worked was to both change the path in the shared library as follows, and then rebuild the mysql 2.8.1 rubygem, specifying both my:

# change the path embedded in libmysqlclient.dylib
sudo install_name_tool -change /usr/local/mysql/lib/libmysqlclient.16.dylib  /usr/local/mysql/current/lib/libmysqlclient.16.dylib /usr/local/mysql/current/lib/libmysqlclient.16.dylib

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

Note that this is based on having mysql installed in /usr/local/mysql/current, you'll need to edit the paths to be appropriate for your system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM