命令rails server
会抛出此错误。
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上使用RubyInstaller上的 Ruby 2.0.0 。
我弄清楚问题是什么,但我不知道如何解决它。问题是2.0/
gem中没有任何mysql2-0.3.11-x86-mingw32
目录。这是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
很明显,它需要当前的Ruby版本号,并将其用作路径段来访问某些mysql2
文件。实际上它是mysql2.so
文件。当我使用 Ruby 2.0.0 时,路径段为2.0
:
mysql2/2.0/mysql2
好的,现在让我们看看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的创建者那里读到了这个答案https://stackoverflow.com/a/5368767/1114926。我试过但它没有帮助。它适用于Ruby 1.9.3
,因为有1.9/
目录。但它不适用于Ruby 2.0.0
。
如何解决?
UPD 1:
感谢您的answer。我试过了。不幸的是我有ERROR: Failed to build gem native extension.
错误:
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,RubyInstaller安装它。无法理解它还需要什么。
我已经向mysql2
GitHub页面https://github.com/brianmario/mysql2/issues/364发布了一个问题。还没有答案。
答案 0 :(得分:13)
在使用Ruby 2.0.0和DevKit 4.7的Windows 7 x64上存在完全相同的问题。
以下步骤帮助了我。
gem uninstall mysql2
从http://cdn.mysql.com/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip
将其解压缩为 C:\ connector-6.0.2
gem install 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 install mysql2 --platform = ruby - --with-opt-dir =“C:\ connector-6.0.2”
答案 1 :(得分:5)
卸载mysql2-0.3.11-x86-mingw32
,在Ruby200
之前编译的gems将无效。你必须自己编译。
如果您运行gem uninstall mysql2
并且列出了非编译版本,则只需卸载mysql2-0.3.11-x86-mingw32
- 编译后的其他版本......
安装
gem install mysql2 --platform=ruby
。那会有用。
按照本指南安装devkit http://rubyonwindowsguides.github.com/book/ch02-04.html。
然后再试一次。
答案 2 :(得分:2)
当我尝试在Windows XP上安装Redmine时,行为完全相同
目前,我被困在那里......但如果有人有任何事情可以让我继续前进,那将是非常受欢迎的。 我会随时了解情况
安托
答案 3 :(得分:2)
我几乎和@odiszapc描述的一样。卸载旧的gem,下载mysql-connector-c-noinstall,解压缩,但最后我用这个命令构建了原生gem:
gem install mysql2 --platform=ruby -- --with-opt-dir=/c/connector-6.0.2
(如果你使用git-bash,那么你可以使用unix样式目录语法。)
答案 4 :(得分:2)
从该链接复制粘贴:https://github.com/brianmario/mysql2/issues/359。它对我有用。
如果在安装gem之后出现错误:
“找不到指定的模块。
C:/Devel/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/lib/mysql2/mysql2.so“
可以通过将libmysql.dll
复制到Ruby的bin文件夹来修复。