MySQL 未初始化的常量 MysqlCompat::MysqlRes(使用 mms2r gem)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1332207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:58:32  来源:igfitidea点击:

uninitialized constant MysqlCompat::MysqlRes (using mms2r gem)

mysqlruby-on-railsrake

提问by Anon

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.

将我的一个 rails 应用程序移到新服务器上,并且必须安装一些 gem 依赖项。但是,在安装 mysql gem 后,每当我尝试运行涉及 mysql 数据库的 rake 命令时,都会收到错误未初始化的常量 MysqlCompat::MysqlRes。似乎只有在需要 mms2r gem 时才会出现此错误。有没有人听说过这个?我正在运行 mysql 2.8.1 gem。

回答by Markus Strauss

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:

在我的 Mac OS X 10.6 上,我这样做是为了安装 2.8.1 gem,它与我的 MacPorts mysql5-server 完美配合:

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

回答by Steven Chanin

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.

基本上问题是找不到动态库libmysqlclient。上述解决方案将起作用,但您需要在任何时候重建 gem 或安装新版本的 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:

另一种方法是将包含库的 MySQL 目录添加到您的动态加载路径。将以下内容放在我的 .bashrc 文件中解决了这个问题:

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

回答by Kuba

My problem was due to my "mysql" being a 32-bit installation while ruby was 64 and 32-bit. Check with these commands

我的问题是由于我的“mysql”是 32 位安装,而 ruby​​ 是 64 位和 32 位。检查这些命令

 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

两者都应匹配 Mach-O 64 位可执行文件 x86_64 或 Mach-O 64 位可执行文件 i386。我安装了一个64位的mysql,然后

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!

瞧!

回答by Greg L.

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

如果您有 mysql 5.5,请按照以下步骤操作: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.

FTR:如果我不需要一些愚蠢的代表来投票,我会投票赞成相同的答案,认为这是我的赞成票。

回答by Greg L.

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

是的,我看到了类似的错误消息,寻找相同的不存在的类 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.

事实证明,该类不应该存在;该错误信息是由最新的 Mysql 驱动程序问题引起的。mysql-2.8.1 在一个目录中查找我的库,该目录最后以额外的 'mysql' 级别命名。例如,我的库(在 MacOS X 10.5.8 下)在 /usr/local/mysql/lib 中,但 mysql.bundle 库在 /usr/local/mysql/lib/mysql ...这是错误的。

I found it easy enough to fix, by creating a symbolic link in the /usr/local/mysql/lib named 'mysql', which points to '.'

我发现通过在 /usr/local/mysql/lib 中创建一个名为 'mysql' 的符号链接指向 '.' 很容易修复。

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

由于这似乎是最近的发展并且我没有看到任何直接的回应,我想我会分享我是如何修复它的。祝你好运 :)

回答by Greg L.

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

gem install -v=2.7.1 也会修复它。

回答by J?rg Battermann

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

在 gem(重新)安装时设置正确的 ARCHFLAGS 对我有帮助..不需要任何符号链接:

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

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

回答by Dafydd Rees

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

在将 Ubuntu 从 9.10 升级到 10.04 后,我出现了这个问题。

It appears to be a problem with the mysql gem.

这似乎是 mysql gem 的问题。

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

症状:任何需要连接到 mysql 的 ActiveRecord 使用都会产生来自“未初始化常量 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.

我尝试了“gem update mysql”,发现无法构建原生扩展,因为编译器找不到mysql_client库。该库 (libmysqlclient.so.16) 位于 /usr/lib 中。

Fix for ubuntu 10.04:

修复 ubuntu 10.04:

As root, I did these:

作为 root,我做了这些:

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.)
  • 操作系统版本- 您使用的是哪个版本?
  • 在哪里以及如何安装mysql?- 这里的人似乎已经从 /usr/local 下的源代码安装了他们的 mysql(我通过 ubuntu 打包系统安装了我的)
  • 你是64 位 ubuntu 还是 32 位?(我目前在 32 位。)

回答by garno

With mysql gem (2.8.1) I was getting

使用 mysql gem (2.8.1) 我得到了

uninitialized constant MysqlCompat::MysqlRes

未初始化的常量 MysqlCompat::MysqlRes

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

使用 -v 2.7 使其完美运行,也适用于使用 Homebrew 安装 mysql 的人

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

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.

请注意,您可以根据需要更改 mysql 版本。

回答by Kialeve

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.

这对我有用。