簡體   English   中英

安裝mysql的Rails - 安裝mysql2時出錯:錯誤:無法構建gem原生擴展

[英]Rails installing mysql - Error installing mysql2: ERROR: Failed to build gem native extension

我有一個Rails 3.2.13應用程序,我想部署,但托管服務將需要MySQL,而不是我一直在使用的sqlite。

在從sqlite轉換為MySQL的過程中,我不得不安裝ruby gem mysql2 ,它在安裝時給出了以下錯誤:

安裝mysql2時出錯:錯誤:無法構建gem原生擴展。

我已經嘗試了bundle install ,以及gem install mysql2 ,但出現了相同的錯誤消息。

我知道對許多人有效的解決方案是sudo apt-get install libmysql-ruby libmysqlclient-dev ,但是我在Windows上使用Git Bash,所以我發現了Windows等價物(@ francois對這個問題的回答)。 我使用安裝程序安裝了MySQL Server 5.6 ,並運行以下命令:

gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.6\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.6\include"' 

根據我的閱讀,這應該成功安裝'mysql2'ruby gem。 但奇怪的是,我仍然有以下錯誤:

  Temporarily enhancing PATH to include DevKit... Building native extensions with: '--with-mysql-lib="c:\\Program 

Files \\ MySQL \\ MySQL Server 5.6 \\ lib“--with-mysql -include =”c:\\ Program Files \\ MySQL \\ MySQL Server 5.6 \\ i nclude“'這可能需要一段時間...錯誤:安裝mysql2時出錯:ERROR :無法構建gem原生擴展。

  c:/RailsInstaller/Ruby1.9.3/bin/ruby.exe extconf.rb --with-mysql-lib="c:\\Pro gram Files\\MySQL\\MySQL Server 5.6\\lib" --with-mysql-include="c:\\Program Files\\My SQL\\MySQL Server 5.6\\include" checking for rb_thread_blocking_region()... yes checking for rb_wait_for_single_fd()... yes checking for rb_hash_dup()... yes 

檢查rb_intern3()...是檢查-llibmysql中的main()...是檢查mysql.h ...是檢查errmsg.h ...是檢查mysqld_error.h ...是創建Makefile

  make generating mysql2-i386-mingw32.def compiling client.c client.c: In function 'rb_raise_mysql2_error': client.c:139:3: 

警告:ISO C90禁止混合聲明和代碼client.c:在函數'finish_and_mark_inactive'中:client.c:508:3:警告:ISO C90禁止混合聲明和代碼client.c:在函數'rb_mysql_client_abandon_results'中:client.c: 535:3:警告:ISO C90禁止混合聲明和代碼client.c:在函數'rb_mysql_client_next_result'中:client.c:938:5:警告:ISO C90禁止混合聲明和編譯mysql2_ext.c編譯result.c結果的代碼。 c:在函數'rb_mysql_result_fetch_fields'中:result.c:407:35:警告:有符號和無符號整數表達式離子之間的比較鏈接共享對象mysql2 / mysql2.so client.o:在函數nogvl_connect': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/cl ient.c:158: undefined reference to mysql_real_connect @ 32'client.o:在函數nogvl_init': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/cl ient.c:150: undefined reference to mysql_init @ 4'client.o:在func中 set_ssl_options': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/cl ient.c:1078: undefined reference to mysql_ssl_set @ 24'客戶端的set_ssl_options': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/cl ient.c:1078: undefined reference to .o:函數mysql_client_options': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/cl ient.c:723: undefined reference to mysql_options的mysql_client_options': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/cl ient.c:723: undefined reference to @ 12'c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:727:對mysql_error@4' client.o: In function未定義引用mysql_error@4' client.o: In function rb_mysql_info'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:267:對mysql_info@4' client.o: In function未定義引用mysql_info@4' client.o: In function rb_mysql_client_warning_count'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / client.:257:undefined引用mysql_warning_count@4' client.o: In function nogvl_do_result'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / client.c :370:對mysql_store_result@4' client.o: In function未定義引用 mysql_store_result@4' client.o: In function rb_mysql_client_more_results'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / client.c:923 :未定義引用mysql_more_results@4' client.o: In function nogvl_select_db'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / client .c:863:未定義引用mysql_select_db@8' client.o: In function nogvl_ping'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:894:對mysql_ping的未定義引用mysql_ping@4' client.o: In function rb_mysql_client_thread_id'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3。 13 \\ ext \\ mysql2 / cl ient.c:856:未定義引用mysql_thread_id@4' client.o: In function rb_mysql_client_last_id'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:825:對mysql_insert_id@4' client.o: In function未定義引用mysql_insert_id@4' client.o: In function nogvl_read_query_result'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9。 1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:357:未定義引用mysql_read_query_result@4' client.o: In function rb_mysql_client_server_info'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:788:未定義引用mysql_get_server_version@4' c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/cl ient.c:789: undefined reference to mysql_get_server_info @ 4'client.o:在函數rb_mysql_client_info': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/cl ient.c:756: undefined reference to mysql_get_client_version @ 0'c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:757:未定義引用mysql_get_client_info@0' client.o: In function rb_mysql_client_real_escape'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:662:對mysql_real_escape_string@16' client.o: In function未定義引用mysql_real_escape_string@16' client.o: In function finish_and_mark_i中 nactive':c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:515:對mysql_free_result@4' client.o: In function未定義引用mysql_free_result@4' client.o: In function nogvl_send_query'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:334:對mysql_send_query@12' client.o: In function未定義引用mysql_send_query@12' client.o: In function nogvl_close':c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:190:undefined引用mysql_close@4' client.o: In function rb_mysql_client_escape'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / client.c :238:未定義引用mysql_escape_string@12' client.o: In function rb_raise_mysql2_error'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:125:未定義引用mysql_error@4' c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/cl ient.c:126: undefined reference to mysql_sqlstate @ 4'c:\\ RailsIn的mysql_error@4' c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/cl ient.c:126: undefined reference to staller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:140:未定義引用mysql_errno@4' client.o: In function rb_connect' :c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:297:未定義引用mysql_errno@4' client.o: In function rb_mysql_client_store_result'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / client.:996:未定義引用mysql_errno@4' client.o: In function rb_mysql_client_next_result'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / client.c:939:undefined reference to mysql_next_result@4' client.o: In function rb_mysql_client_affected_rows'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / client.c:839 :未定義的對mysql_affected_rows@4' client.o: In function引用mysql_affected_rows@4' client.o: In function rb_mysql_client_async_result'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / client .c:419:你 ndefined引用mysql_errno@4' client.o: In function rb_mysql_client_abandon_results'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / client。 c:539:未定義引用mysql_next_result@4' c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/cl ient.c:538: undefined reference to mysql_more_results @ 4'c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:547:未定義引用mysql_free_result@4' client.o: In function nogvl_do_result'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / client.c:368:undefined reference到mysql_use_result@4' client.o: In function nogvl_close':c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c: 190:未定義引用mysql_close@4' client.o: In function set_charset_name'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / cl ient.c:1067:undefined referen ce to mysql_options@12' c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/cl ient.c:1069: undefined reference to mysql_error @ 4 'client.o:在函數init_mysql2_client': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/cl ient.c:1105: undefined reference to mysql_get_client_info @ 0'come.o:在函數rb_mysql_result_count': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/re sult.c:576: undefined reference to mysql_num_rows的rb_mysql_result_count': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/re sult.c:576: undefined reference to @ 4'rend.o:在函數rb_mysql_result_fetch_field': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/re sult.c:126: undefined reference to mysql_fetch_field_direct @ 8'c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / re sult.c:114 :未定義的對mysql_num_fields@4' result.o: In function引用mysql_num_fields@4' result.o: In function rb_mysql_result_fetch_fields'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / re sult .c:403:你 ndefined對mysql_num_fields@4' result.o: In function引用mysql_num_fields@4' result.o: In function nogvl_fetch_row'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / re sult。 c:105:未定義引用mysql_fetch_row@4' result.o: In function rb_mysql_result_free_result'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / re sult.c:75:對mysql_free_result@4' result.o: In function未定義引用mysql_free_result@4' result.o: In function rb_mysql_result_fetch_row'中:c:\\ RailsInstaller \\ Ruby1.9.3 \\ lib \\ ruby​​ \\ gems \\ 1.9.1 \\ gems \\ mysql2-0.3.13 \\ ext \\ mysql2 / re sult.c:213:未定義引用mysql_fetch_lengths@4' c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/re sult.c:215: undefined reference to mysql_num_fields @ 4'rend.o:函數rb_mysql_result_each': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/re sult.c:503: undefined reference to mysql_fetch_fields的rb_mysql_result_each': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/re sult.c:503: undefined reference to @ 4'rend.o:在函數rb_mysql_result_free_result': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/re sult.c:75: undefined reference to rb_mysql_result_free_result': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/re sult.c:75: undefined reference to mysql_free_result的rb_mysql_result_free_result': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/re sult.c:75: undefined reference to @ 4'rend.o:在函數rb_mysql_result_each': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/re sult.c:531: undefined reference to mysql_fetch_fields @ 4'sult.o:在函數rb_mysql_result_free_result': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/re sult.c:75: undefined reference to mysql_free_result的rb_mysql_result_free_result': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/re sult.c:75: undefined reference to @ 4'sult.o:在函數rb_mysql_result_each': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/re sult.c:490: undefined reference to mysql_num_rows @ 4'rend.o:在函數rb_mysql_result_free_result': c:\\RailsInstaller\\Ruby1.9.3\\lib\\ruby\\gems\\1.9.1\\gems\\mysql2-0.3.13\\ext\\mysql2/re sult.c:75: undefined reference to mysql_free_result @ 4' collect2:ld返回1退出狀態make:*** [mysql2.so]錯誤1

  Gem files will remain installed in c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9 .1/gems/mysql2-0.3.13 

檢查。 結果記錄到c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0。 3.13 / EXT / mysql2 / gem_make.out

 Can anyone please help? I am having much trouble comprehending what's wrong with the installation. 

我在Win64環境中遇到了同樣的錯誤。

我測試了很多解決方案,但唯一對我有用的是:

  • gem install mysql2 -v'0.3.11'

我一直對同樣的問題感到惱火,終於成功安裝了mysql2 感謝odiszapc @ github 看來我通過谷歌發現的任何其他解決方案都不適用於我。

復制並粘貼在這里 所以沒有信任我。

gem uninstall mysql2

Download last MySQL connector from http://cdn.mysql.com/Downloads/Connector-C/mysql-    connector-c-noinstall-6.0.2-win32.zip

Extract it to 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"'

關於我的其他信息。

  • ruby 1.9.3p392(2013-02-22)[i386-mingw32]
  • Rails 3.2.13
  • MySQL Server 5.6
  • mysql2-0.3.13

PS即使您成功安裝了mysql2 ,您可能仍需要一些工作(例如mysql2.so(LoadError)),並且在我的情況下它與libmysql有關,似乎是另一個關於mysql2的重大故障。

我在Windows 7 64位上安裝。 對我有用的是:

從以下網址下載C 32位連接器存檔: http//dev.mysql.com/downloads/connector/c/

我把它提取到C:\\ Temp。 如果使用其他目錄,請調整下一個命令。

gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:\Temp\mysql-connector-c-6.1.3-win32"'

痛苦......很痛苦。 最后工作做:

(平台:Windows64bits,Ruby32bits,DevKit32bits ......)

  1. http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick下載C語言的mysql連接器
  2. 在名稱中沒有空格的目錄中解壓縮連接器!
  3. 將lib / libmysql.dll文件復制到ruby / bin中
  4. gem install mysql2 - --with-mysql-dir = D:\\ RoR \\ mysql-connector-c(所以給連接器的目錄而不是服務器的目錄)

我啟動並運行了mysql2 v0.3.17 ...

  1. 從下載Mysql連接器
    http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick
  2. 提取它。 復制lib \\ libmysql.dll文件並將其粘貼到Ruby的bin目錄ex: C:\\ RailsInstaller \\ Ruby1.9.3 \\ bin
  3. 現在再次安裝Mysql2 gem
    gem install mysql2 - ' - with-mysql-lib =“c:\\ Program Files \\ MySQL \\ MySQL Server 5.0 \\ lib \\ opt”--with-mysql-include =“c:\\ Program Files \\ MySQL \\ MySQL Server 5.0 \\包括“”
    注意:根據您的需要更改mysql安裝路徑
  4. 嘗試現在捆綁

暫無
暫無

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

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