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

Rah*_*hul 64 mysql windows ruby-on-rails 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)
Run Code Online (Sandbox Code Playgroud)

我怎样才能纠正它?

chr*_*sto 100

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

> 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.
Run Code Online (Sandbox Code Playgroud)

  • 轻松最好的答案. (13认同)

ant*_*ome 85

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

背景:我在我的Windows机器上本地安装了Rails 3,mysql2 gem和MySQL社区服务器版本5.5.21(32位).我libmysql.dll从MySQL安装中抓取了客户端库()并将其复制到我的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
Run Code Online (Sandbox Code Playgroud)

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

参考链接

  • 这对我有用,但下载位置被破坏除外.新的下载页面http://dev.mysql.com/downloads/connector/c/.选择"Windows(x86,32位),ZIP存档" (6认同)

use*_*594 9

如果您使用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
Run Code Online (Sandbox Code Playgroud)

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

gem pristine mysql2 -- --with-mysql-config=C:\mysql-connector-c-noinstall-6.0.2-win32    
Run Code Online (Sandbox Code Playgroud)

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