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

当尝试通过我的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) 

我该如何纠正?

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

背景:我在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 

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

引用的链接

卸载并重新安装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. 

如果您使用的是64位版本的mysql和32位版本的ruby,请在http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using -ruby与-它/

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

对于Ruby 1.9.2:

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

对于Ruby 1.9.3 :(显示mysql2变体)

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

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

我发现了这个问题的一个完全不同的原因。 我一直在使用MySQL的gem。 我build立了mysql2的gem,但我忘了更新我的database.yml。 用mysql2创业板,它需要说:

  development: adapter: mysql2 

而不是

  development: adapter: mysql 

gem已经build成了,但是当我下次跑耙时,我得到了错误。

显然,一旦你看到它,但你得到了同样的错误信息,在这里讨论!

顺便说一下,在我的机器上构buildmysql2 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" 

我有这样一个问题:

 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两个版本。 我不知道如何。 当我捆绑它自动select5.5.29版本。 我卸载了那个,然后重新安装了我的gem,并解决了这个问题。

添加到现有的答案。 (windows平台专用)

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

为了得到这个可以工作的东西,你需要2件事情。 mysql2 gemlibmysql.dll ,你需要匹配它们的版本。 ( 这引起了我的困惑,因为我可以看到最新的连接器是6.x而mysql只有5.x,我应该如何匹配它们

mysql2gem 。 当你安装它时你需要指定连接器。

  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 succesfully =>我的情况是因为我的MySQL太旧(为什么ruby会照顾)。 所以我从甲骨文得到一些最新的MySQL。 在它下面使用lib include libmysql.dll你并不需要升级你的数据库,你可以将它保留在某个地方,并且在生成所需的两个组件后继续使用它

我的情况:我使用一个非常古老的mysql数据库,我不愿意现在升级它。 所以我把这个数据库备份起来,稍后恢复

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

我有同样的问题,我解决了以下问题:

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

2 ::解压缩项目的“ Provider ”文件夹中的文件( libmysql.dll )。

3:沃尔沃一个运行命令bundle install

准备好了,解决了!

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