uninitialized constant MysqlCompat::MysqlRes (usin

2019-01-11 02:01发布

问题:

moved a rails app of mine onto a new server and had to install a few gem dependencies. However, after installing the mysql gem I get the error, uninitialized constant MysqlCompat::MysqlRes, whenever I try to run a rake command that involves the mysql database. It seems I only get this error when I require the mms2r gem. Has anyone ever heard of this? I'm running mysql 2.8.1 gem.

回答1:

on my Mac OS X 10.6 I did this to install the 2.8.1 gem, which worked perfectly with my MacPorts mysql5-server:

sudo env ARCHFLAGS="-arch x86_64" gem install mysql


回答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"


回答3:

My problem was due to my "mysql" being a 32-bit installation while ruby was 64 and 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 64-bit mysql, then

export ARCHFLAGS="-arch x86_64" ; 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

and voila!



回答4:

If you have mysql 5.5 follow this: http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/

FTR: If I didn't need some stupid rep to upvote I would have upvoted the identitcal answer, consider this my upvote.



回答5:

Yes, I saw a similar error message, looking for the same nonexistent class MysqlCompat::MysqlRes

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 found it easy enough to fix, by creating a symbolic link in the /usr/local/mysql/lib named 'mysql', which points to '.'

So when the libraries are referenced at that extra depth, they are found, and work. This is definitely a hack; I'm sure there are more appropriate ways to fix this. I just need it to work so I can get on with other things.

Moreover, this may not work for you. It is likely to work if your error looks like:

  ./mysql.bundle: dlopen(./mysql.bundle, 9): Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib (LoadError)
  Referenced from: /Users/ccullen/Projects/npapp-v2/mysql-ruby-2.8.1/mysql.bundle
  Reason: image not found - ./mysql.bundle
    from test.rb:5

Since this seems to be a recent development and I hadn't seen any direct response to it, I thought I'd share how I fixed it. Good luck :)



回答6:

gem install -v=2.7.1 will fix it as well.



回答7:

Setting the proper ARCHFLAGS upon gem (re-)installation helped me.. without any symlinking required:

http://joergbattermann.tumblr.com/post/181479575/fixing-the-nameerror-uninitialized-constant



回答8:

This problem appeared with me, after upgrading Ubuntu from 9.10 to 10.04.

It appears to be a problem with the mysql gem.

Symptoms: Any use of ActiveRecord that requires a connection to mysql yields a stack trace coming from "uninitialized constant MysqlCompat::MysqlRes"

I tried a "gem update mysql" and found that I couldn't build native extensions because the compiler can't find the mysql_client library. That library (libmysqlclient.so.16) sits in /usr/lib.

Fix for ubuntu 10.04:

As root, I did these:

apt-get install libmysqlclient-dev
gem install mysql

I notice that several different people are trying things here and I wonder if we're not locating the root cause.

Variables that people need to clarify in their answers:

  • operating system version - which version of what are you using?
  • where and how did you install mysql? - people here seem to have installed their mysql from source under /usr/local (I installed mine through the ubuntu packaging system)
  • are you on a 64bit ubuntu or 32bit? (I'm currently on 32 bit.)


回答9:

With mysql gem (2.8.1) I was getting

uninitialized constant MysqlCompat::MysqlRes

Using -v 2.7 make it work perfectly and for those who used Homebrew to install mysql

sudo gem install mysql -v 2.7 -- --with-mysql-config=/usr/local/Cellar/mysql/5.1.48/bin/mysql_config

Note that you can change mysql version if needed.



回答10:

sudo gem install mysql -v 2.7 should do the trick...



回答11:

sudo gem install mysql -v 2.7 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config also did the trick for me when migrating over to my new Snow Leopard laptop. I did not use MacPorts to install mysql, but rather the binary, and had no luck with the arch flag solutions or symlinks.



回答12:

I tried everything else here, but still got the problem. Downgrading from MySQL 5.5 to 5.1 fixed it for me. (Mac OS X 10.6.5)



回答13:

Downgrade (from 5.9) to mysql 5.1 helped on 10.6 ... running both mysql and mysql2 gems.



回答14:

The mysql and mysql2 gems both work on ruby 1.9.2 just update ruby and install the gem you need.



回答15:

gem uninstall mysql

gem install mysql -v 2.7 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

ldconfig /usr/local/mysql/lib/mysql

RAILS_ENV=production rake db:migrate --trace

This worked for me.



回答16:

sudo apt-get install libmysqlclient15-dev


回答17:

I've tried all of the above and none of them work for me either. When trying to install mysql version 2.7, I get the error:

sudo gem install -v=2.7.1 mysql -- --with-mysql-dir=/usr/local/mysql-5.1.39-osx10.5-powerpc/bin/mysql_config
ERROR:  could not find gem mysql locally or in a repository
F107PHD:stepgreen.org tdillahu$ sudo gem install -v=2.7 mysql -- --with-mysql-dir=/usr/local/mysql-5.1.39-osx10.5-powerpc/bin/mysql_config
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
    ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with-mysql-dir=/usr/local/mysql-5.1.39-osx10.5-powerpc/bin/mysql_config
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
    --with-mysql-config
    --without-mysql-config
    --with-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mlib
    --without-mlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-zlib
    --without-zlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-socketlib
    --without-socketlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-nsllib
    --without-nsllib
    --with-mysqlclientlib
    --without-mysqlclientlib


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.7/gem_make.out

My original error: ake aborted! uninitialized constant MysqlCompat::MysqlRes /vendor/rails/activesupport/lib/active_support/dependencies.rb:440:in load_missing_constant' /vendor/rails/activesupport/lib/active_support/dependencies.rb:80:inconst_missing'



回答18:

I had the same problem after upgrading from Fedora 10 to Fedora 12. I fixed it by just uninstalling mysql gem and installing it again. So it complies with the new version of MySQL.



回答19:

sudo gem install mysql -v 2.7 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Worked perfectly for me :)



回答20:

On Mac OS X 10.6.4, I had to specify the architecture and config directory:

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



回答21:

If your Mysql version is 5.5 you should uninstall it. I just left an article about using mysql with ruby : http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/



回答22:

This is what worked for me. I read a ton of posts and found that using the system ruby install was causing an incompatibility issue:

  1. don't use default ruby install! install ruby with macports
  2. don't use default rubygems install! install rb-rubygems with macports
  3. use mysql 5.1 (not 5.5) - installed from mysql.com mac .dmg
  4. 4.

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



回答23:

sudo env ARCHFLAGS="-arch x86_64" gem install mysql

Dmg package from the mysql site an ddone!



回答24:

sudo gem install mysql -v 2.7 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config 

also worked for me when arch flag and symlinks didnt! THANKS!!



回答25:

How is the mysql dependency related to mms2r? I'm the mms2r author, btw.

The mms2r gemspec https://github.com/monde/mms2r/blob/master/mms2r.gemspec does not list a mysql dependency.