簡體   English   中英

Rails Server導致Mysql2出錯

[英]Rails Server causes error with Mysql2

我在Windows 7機器上運行Rails 3.2和Ruby 2.0。 我終於安裝了Mysql2(至少我是這么認為的)。 我可以毫無問題地運行“bundle install”,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>'

我的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

看起來像mysql2的標准mingw32問題

-

問題是,由於Windows未安裝MYSQL,您必須從頭開始安裝。 看來你已經對此有所了解,但是因為有一個新版本的mysql2 ,你必須更新你的C-Connector標題

我們在這里寫了一個關於如何做到這一點教程

-

固定

我會這樣做:

  1. gem uninstall mysql2
  2. 下載最新的32位版本的mysql c-connector
  3. 保存zip文件並將其解壓縮到沒有空格的目錄中
  4. 進入你的系統后,輸入cmd: gem install mysql2 —platform=ruby — '—with-mysql-dir=”C:\\mysql-connector-path”'
  5. 最后,將libmysql.dllmysql/bin目錄復制到ruby/bin目錄
  6. 刪除mysql c-connector文件

應該為您安裝,以便您可以毫無問題地使用它

先做:

gem uninstall mysql2

然后做:

Bundle install

它發生在我從ubuntu 14.04升級到16.04時 我做了以上兩個步驟,並糾正了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM