我在Windows 7机器上运行Rails 3.2和Ruby 2.0。 我终于安装了Mysql2(至少我是这么认为的)。我可以运行"捆绑安装"没问题,mysql2 v.0.3.16显示在我的gem包中。
但是当我运行" gem install mysql2"由于本机扩展而失败。 现在我正在尝试运行" rails s"启动我的服务器,我收到更多错误。
Stealth@STEALTH-PC ~/Documents/GitHub/flitti (tony-dev)
$ rails s
DL is deprecated, please use Fiddle
c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/mysql2-0.3.16/lib/mysql2.rb
:8:in `require': cannot load such file -- mysql2/mysql2 (LoadError)
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/mysql2-0.3.16/
lib/mysql2.rb:8:in `<top (required)>'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:72:in `require'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:70:in `each'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:70:in `block in require'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:59:in `each'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:59:in `require'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler.rb:132:in `require'
from c:/Users/Stealth/Documents/GitHub/flitti/config/application.rb:7:in
`<top (required)>'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-3.2.1
2/lib/rails/commands.rb:53:in `require'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-3.2.1
2/lib/rails/commands.rb:53:in `block in <top (required)>'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-3.2.1
2/lib/rails/commands.rb:50:in `tap'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-3.2.1
2/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
My Gemfile看起来像这样
source 'https://rubygems.org'
gem 'rails', '3.2.12'
gem 'foundation-rails'
gem 'mysql2'
gem 'merit'
gem 'devise'
gem 'paperclip', '3.4.0'
gem 'pry'
gem 'mailboxer'
gem 'simple_form'
gem 'thumbs_up'
gem 'jquery-rails'
gem 'faye'
gem 'private_pub', :git => 'git://github.com/ryanb/private_pub.git'
gem 'thin'
gem 'pjax_rails'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
group :development, :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
end
group :test do
gem 'faker'
gem "capybara"
gem "guard-rspec"
gem "launchy"
end
我如何解决这个问题,以便让我的rails服务器正常工作?
原生扩展错误:
Stealth@STEALTH-PC /c
$ gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:\mysql-connector-c
"'
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-dir="C:\mysql-connector-c"'
This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
c:/RailsInstaller/Ruby2.0.0/bin/ruby.exe extconf.rb --with-mysql-dir="C:\mys
ql-connector-c"
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Cannot find include dir(s) C:\mysql-connector-c/include
-----
*** 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:/RailsInstaller/Ruby2.0.0/bin/ruby
--with-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/
--with-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
Gem files will remain installed in c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0
.0/gems/mysql2-0.3.16 for inspection.
Results logged to c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/mysql2-0.
3.16/ext/mysql2/gem_make.out
答案 0 :(得分:3)
看起来像mingw32
mysql2
问题
-
问题在于,由于Windows未安装MYSQL,因此您必须从头开始安装。您似乎已经对此有所了解,但因为有mysql2
的新版本,您必须更新C-Connector标题
我们写了tutorial on how to do this here
-
<强>修正强>
我会这样做:
gem uninstall mysql2
- Download the latest 32-bit version of mysql c-connector
- 保存zip文件&amp;将其解压缩到没有空格的目录
- 在您的系统上,将其输入cmd:
gem install mysql2 —platform=ruby — ‘—with-mysql-dir=”C:\mysql-connector-path”’
- 最后,将
libmysql.dll
目录中的mysql/bin
复制到ruby/bin
目录- 删除mysql c-connector文件
醇>
此应该为您安装它,以便您可以毫无问题地使用它
答案 1 :(得分:0)
首先:
gem uninstall mysql2
然后做:
Bundle install
当我从ubuntu 14.04 升级到 16.04 时,就发生了这种情况。 我做了以上两个步骤并且纠正了。