mysql2 gem编译为错误的mysql客户端库

时间:2012-01-05 10:22:32

标签: mysql ruby-on-rails windows mysql2

当尝试通过我的rails应用程序连接到mysql服务器时,出现以下错误

D:/Program_Files/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': 
Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the client library is 5.0.27. (RuntimeError)

我该如何纠正?

8 个答案:

答案 0 :(得分:99)

卸载并重新安装gem通常可以解决此问题,无需手动下载和移动文件。从您的rails应用程序目录:

> gem uninstall mysql2

You have requested to uninstall the gem:
    mysql2-0.3.11
database_cleaner-0.9.1 depends on [mysql2 (>= 0)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn]  Y
Successfully uninstalled mysql2-0.3.11

> bundle install

Fetching gem metadata from http://rubygems.org/......
Fetching gem metadata from http://rubygems.org/..
Using rake (0.9.2)
Using i18n (0.6.1)
... <SNIP> ...
Installing mysql2 (0.3.11) with native extensions
... <SNIP> ...
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

答案 1 :(得分:85)

我和你有同样的问题,或者至少症状是一样的。

背景:我在我的Windows机器上本地安装了Rails 3,mysql2 gem和MySQL社区服务器版本5.5.21(32位)。我从MySQL安装中抓取了客户端库(libmysql.dll)并将其复制到我的ruby安装的bin文件夹中。

当我运行bundle exec rake db:create时,我收到了与您相同的错误消息,我想“嘿,当我从最新的MySQL版本中获取它时,客户端库如何过时?”

当您gem install mysql2时会显示一条有用的消息。不幸的是,如果你用Bundler安装gem,Bundler会吃掉这条消息。这是:

=========================================================================
You've installed the binary version of mysql2. It was built using MySQL 
Connector/C version 6.0.2. It's recommended to use the exact same version
to avoid potential issues.

At the time of building this gem, the necessary DLL files where available
in the following download:

http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick

And put lib\libmysql.dll file in your Ruby bin directory, for example
C:\Ruby\bin

按照这些说明解决了我的问题。

Referenced link

答案 2 :(得分:9)

如果您使用的是64位版本的mysql和32位版本的ruby,请在http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/上查看此解决方案

你基本上必须从mysql网站下载一个连接器,并用你下载的连接器编译mysql或mysql2。

for Ruby 1.9.2:

gem install mysql --platform=ruby -- --with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32

for Ruby 1.9.3 :(显示mysql2变体)

gem pristine mysql2 -- --with-mysql-config=C:\mysql-connector-c-noinstall-6.0.2-win32    

请注意,在提取MySQL Connector / C的目录中使用正斜杠。

答案 3 :(得分:2)

我遇到了这样的问题:

Incorrect MySQL client library version! This gem was compiled for 5.5.29 but the client library is 5.6.17.

对我来说,问题是我的机器上安装了5.5.29和5.6.17两个版本。我不知道怎么做。当我捆绑它时自动选择5.5.29版本。我卸载了那个,然后重新安装了我的宝石,这解决了问题。

答案 4 :(得分:1)

我发现了这个问题的完全不同的原因。我一直在使用mysql gem。我构建了mysql2 gem,但我忘了更新我的database.yml。使用mysql2 gem,需要说:

  development:
    adapter: mysql2

而不是

  development:
    adapter: mysql

构建了宝石,但是当我下次运行rake时,我收到了错误。

很明显,一旦你看到它,但你得到的错误信息与此处讨论的相同!

顺便说一下,在我的机器上构建mysql2 gem的命令比上面描述的要复杂一点:

gem install mysql2 -- --with-mysql-lib="c:\mysql-connector-c-noinstall-6.0.2-win32\lib"  --with-mysql-include="c:\mysql-connector-c-noinstall-6.0.2-win32\include" --with-mysql-dir="c:\mysql-connector-c-noinstall-6.0.2-win32"

答案 5 :(得分:1)

添加到现有答案。 (具体是windows平台)

Ruby真的很糟糕。 Rails实际上不应该关心连接器的版本或mysql版本。 - 但这是我的意见。

为了让这件事变得有效,你需要做两件事。 mysql2 gemlibmysql.dll,您需要根据版本进行匹配。 (这给我带来了困惑,因为我可以看到最新的连接器是6.x而mysql只有5.x,我该如何匹配它们

mysql2 gem 。当你安装它时,你需要指定连接器。

     gem install mysql2 --platform=ruby -- 
     --with-mysql-lib="d:\mysql\lib" --with-mysql-include="d:\mysql\include"

不需要从oracle下载连接器。你需要的只是一个mysql安装和它下面的lib include文件夹。然后将libmysql.dll放在railsinstaller bin文件夹下。

如果不能让你成功安装mysql2 gem,对于我的情况来说,这是因为我的mysql太旧了(为什么ruby会这么做)。所以我从oracle获得了一些最新的mysql。使用其下的lib include libmysql.dll您不需要升级数据库,可以将其保留在某处并在生成2个必需组件后继续使用

我的情况:我使用了一个非常古老的mysql数据库,目前我不愿意升级它。所以我将该数据库备份并稍后恢复

答案 6 :(得分:1)

在我的情况下在Windows上,错误地将libmysql.dll从MySQL Server 5.5目录复制到ruby200 / bin。正确的是从mysql-connector-c-noinstall-6.0.2-win32复制libmysql.dll。

答案 7 :(得分:-1)

我遇到了同样的问题,我已经解决了以下问题:

1 :: 从以下链接下载zip:https://dev.mysql.com/downloads/connector/c/

2 :: 解压缩&#34;中的文件( libmysql.dll )的提供商&#34;项目文件夹。

3 :: Volve one运行命令bundle install

准备好了,解决了!

https://dev.mysql.com/downloads/connector/c/