Ruby on rails 3 错误“…”;。。。无法加载这样的文件--mysql2/2.0/mysql2(LoadError)";。在使用Ruby 2.0.0的Windows XP上

Ruby on rails 3 错误“…”;。。。无法加载这样的文件--mysql2/2.0/mysql2(LoadError)";。在使用Ruby 2.0.0的Windows XP上,ruby-on-rails-3,mysql2,ruby-2.0,Ruby On Rails 3,Mysql2,Ruby 2.0,命令rails服务器抛出此错误 C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/mysql2.rb:2:in `require': cannot load such file -- mysql2/2.0/mysql2 (LoadError) 我使用的是Windows XP中的Ruby 2.0.0 我知道问题出在哪里,但不知道如何解决。问题是在mysql2-0.3.11-x86-mingw32ge

命令
rails服务器
抛出此错误

C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/mysql2.rb:2:in `require': cannot load
 such file -- mysql2/2.0/mysql2 (LoadError)
我使用的是Windows XP中的Ruby 2.0.0

我知道问题出在哪里,但不知道如何解决。问题是在
mysql2-0.3.11-x86-mingw32
gem中没有任何
2.0/
目录。这是
rails
作为其依赖项从Gemfile安装的gem:

GEM
  remote: https://rubygems.org/
  specs:
     ... many gems here
     mysql2 (0.3.11-x86-mingw32)
     ... many gems here
DEPENDENCIES
  ...
  mysql2
  ...
这是该
mysql2.rb
文件中的内容:

# C:\Ruby200\lib\ruby\gems\2.0.0\gems\mysql2-0.3.11-x86-mingw32\lib\mysql2\mysql2.rb

RUBY_VERSION =~ /(\d+.\d+)/
require "mysql2/#{$1}/mysql2"  # <<-- this is that #2 line that throws an error
好的,现在让我们看看
mysql2-0.3.11-x86-mingw32
gem的目录是什么样子的:

dir: C:\Ruby200\lib\ruby\gems\2.0.0\gems\mysql2-0.3.11-x86-mingw32\lib\mysql2\

没有任何
2.0/
目录

我知道关于libmysql.dll的问题。我把它放在我的
C:\Ruby200\bin
中。这没用

我从RubyInstaller的创建者那里读到了这个答案。我试过了,但没用。它适用于
Ruby 1.9.3
,因为有
1.9/
目录。但是它不适用于
Ruby 2.0.0

如何解决


UPD 1:

谢谢你的支持。我试过了。不幸的是,我有
错误:无法构建gem本机扩展。
错误:

C:\>gem install mysql2 --platform=ruby
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    C:/Ruby200/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... *** 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=C:/Ruby200/bin/ruby
C:/Ruby200/lib/ruby/2.0.0/mkmf.rb:431:in `try_do': The compiler failed to generate an executable file. (Runtim
eError)
You have to install development tools first.
... other code follows here...
它说:

您必须首先安装开发工具

但是我已经安装了完整的DevKit,rubynstaller安装了它。我不明白它还需要什么


我已经在
mysql2
GitHub页面上发布了一个问题。还没有答案。

卸载
mysql2-0.3.11-x86-mingw32
,在
Ruby200
之前编译的gems将无法工作。你必须自己编译它。 如果您运行
gem uninstall mysql2
,并且列出了一个未编译的版本,则只需卸载
mysql2-0.3.11-x86-mingw32
-编译的版本,否则

装置
gem安装mysql2--platform=ruby
。那就行了

按照本指南安装devkit


然后再试一次。

当我尝试在windows XP上安装Redmine时,行为完全相同

  • 当我尝试执行“rake生成\u secret\u令牌”时,我得到了“无法加载” 这样的文件--mysql2/2.0/mysql2(LoadError)”
  • 当我尝试使用--platform=ruby重新构建mysql2时,我得到了 和你一样,格林
目前,我在那里被绊住了。。。但如果有人能让我继续前进,我将非常欢迎。 我也会随时通知你


antoine在使用Ruby 2.0.0和DevKit 4.7的Windows 7 x64上出现了完全相同的问题

以下步骤帮助了我

  • gem卸载mysql2

  • 从下载最后一个MySQL连接器

  • 将其解压缩到C:\connector-6.0.2

  • gem安装mysql2--platform=ruby----with mysql lib=“C:\connector-6.0.2\lib”--with mysql include=“C:\connector-6.0.2\include”--with mysql dir=“C:\connector-6.0.2”'

  • 甚至更短:

    gem安装mysql2--platform=ruby--opt dir=“C:\connector-6.0.2”


    我几乎做了@odiszapc描述的同样的事情。卸载旧的gem,下载mysql-connector-c-noinstall,解压,但最后我使用这个命令来构建本机gem:

    gem install mysql2 --platform=ruby -- --with-opt-dir=/c/connector-6.0.2
    

    (如果使用git bash,则可以使用unix风格的目录语法。)

    从该链接复制粘贴:。这对我有用


    如果在安装gem后,出现错误:

    “找不到指定的模块。
    C:/Devel/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/lib/mysql2/mysql2.so“


    可以通过将
    libmysql.dll
    复制到Ruby的bin文件夹来修复此问题。

    请注意,如果运行bundle安装或bundle更新,将再次安装mysql2 gem的mingw版本。您必须始终“gem卸载”它…我必须执行gem安装mysql2--platform=ruby--opt dir=/c/connector-6.0.2--mysql dir=/c/connector-6.0.2。。。因为编译失败,我注意到有对${mysql dir}/include的引用。是的,这很有效!但首先-您需要使用cmd.exe,而不是powershell!第二,有时你必须强制gem文件中的gem版本,例如0.3.13,因为bundler正在安装0.2.6-mingw编译版本…如果上面的版本不起作用,请使用以下命令:-gem安装mysql2--platform=ruby----with mysql lib=“C:\connector-6.0.2\lib”--with mysql include=“C:\connector-6.0.2\include”@RohitPorwal yours为我工作过,但是您缺少命令中的最后一个“应该是:gem install mysql2--platform=ruby--”和mysql lib=“C:\connector-6.0.2\lib”--和mysql include=“C:\connector-6.0.2\include”'
    gem install mysql2 --platform=ruby -- --with-opt-dir=/c/connector-6.0.2