2014-06-30 168 views
1

我已經嘗試安裝mysql 2 gem來開始構建我的rails應用程序。我有Rails 4.0.4和Ruby 1.9.3p545。工作了幾天後,我一直得到同樣的錯誤。我試圖再次安裝mysql 32位版本,以確保我的版本與正確的連接器相符,將我的libmysql.dll和libmysql.lib移動到我的ruby/bin文件夾中,並嘗試了其他方式使其可以在網上找到。他們都沒有爲我工作。以下是我的。我將不勝感激任何幫助,讓我最終安裝mysql2寶石。安裝mysql2 gem

PS C:\Users\pc> gem install mysql2 --no-rdoc --no-ri -- '--with-mysql-lib="C:\Program Files\MySQL\ 
.6\lib\" --with-mysql-include="C:\Program Files\MySQL\MySQL Server 5.6\include\"' 
Temporarily enhancing PATH to include DevKit... 
Building native extensions with: '--with-mysql-lib=C:\Program Files\MySQL\MySQL Server 5.6\lib" --with-mys 
Program Files\MySQL\MySQL Server 5.6\include"' 
This could take a while... 
ERROR: Error installing mysql2: 
     ERROR: Failed to build gem native extension. 

    C:/Ruby193/bin/ruby.exe extconf.rb --with-mysql-lib=C:\Program Files\MySQL\MySQL Server 5.6\lib" --wit 
e=C:\Program Files\MySQL\MySQL Server 5.6\include" 
checking for ruby/thread.h... no 
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 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lm... yes 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lz... no 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lsocket... no 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lnsl... no 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lmygcc... no 
checking for mysql_query() in -lmysqlclient... no 
*** 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:/Ruby193/bin/ruby 
     --with-mysql-dir 
     --without-mysql-dir 
     --with-mysql-include 
     --without-mysql-include=${mysql-dir}/include 
     --with-mysql-lib=${mysql-dir}/lib 
     --with-mysql-config 
     --without-mysql-config 
     --with-mysql-dir 
     --without-mysql-dir 
     --with-mysql-include 
     --without-mysql-include=${mysql-dir}/include 
     --with-mysql-lib=${mysql-dir}/lib 
     --with-mysqlclientlib 
     --without-mysqlclientlib 
     --with-mlib 
     --without-mlib 
     --with-mysqlclientlib 
     --without-mysqlclientlib 
     --with-zlib 
     --without-zlib 
     --with-mysqlclientlib 
     --without-mysqlclientlib 
     --with-socketlib 
     --without-socketlib 
     --with-mysqlclientlib 
     --without-mysqlclientlib 
     --with-nsllib 
     --without-nsllib 
     --with-mysqlclientlib 
     --without-mysqlclientlib 
     --with-mygcclib 
     --without-mygcclib 
     --with-mysqlclientlib 
     --without-mysqlclientlib 

extconf failed, exit code 1 

Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.16 for inspection. 
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/extensions/x86-mingw32/1.9.1/mysql2-0.3.16/gem_make.out 
+1

你需要一些MySQL的開發庫,我不知道它是如何工作的窗口,雖然,檢查這一點,可以幫助HTTP://計算器。 com/questions/4115126/ruby​​-gem-mysql2-install-failing –

回答

2

我們寫了一篇關於如何做一個教程這個here

-

有幾個問題與你在做什麼:

  1. 你不能有任何路徑中的空格
  2. 您需要包含最新版本的MYSQL C-Connector

這爲我們工作:

  • 下載最新32位版本的MYSQL C-Connector
  • 安裝到一個路徑沒有空格
  • 使用以下命令:

    gem install mysql2 --platform=ruby -- ‘--with-mysql-dir=」C:\mysql-connector-path」’

這應該正確安裝

+0

我試過了。不幸的是,這導致了對大量不同項目的未定義引用。我不太明白爲什麼會這樣。最後,它說,「失敗,退出代碼2」。問題仍未解決。 – user3694391

+0

我已經完成了你所說的。但是,運行安裝程序不會提供必須解壓縮的zip文件。它只是直接下載文件。然後,當我在終端中傳遞正確的命令時,我收到了大量未定義的引用,如'mysql_error @ 4','mysql_init @ 4','mysql_num_rows @ 4'。請幫幫我。我無法弄清楚這裏有什麼問題。 – user3694391

+2

它終於奏效了!我必須確保將新連接器中的新libmysql.dll文件複製到我的ruby/bin和lib文件夾中。 :) – user3694391