2013-07-25 95 views
3

我有一个Rails 3.2.13应用程序,我想部署,但托管服务需要MySQL,而不是我一直使用的sqlite。Rails安装mysql - 安装mysql2时出错:错误:无法构建gem原生扩展

在从sqlite转换为MySQL的过程中,我必须安装红宝石宝石mysql2,这是给我安装时出现以下错误:

Error installing mysql2: ERROR: Failed to build gem native extension.

我都试过bundle install,以及gem install mysql2,但出现相同的错误消息。

我知道,已经为许多工作的解决方案是sudo apt-get install libmysql-ruby libmysqlclient-dev,但我对使用Git猛砸视窗,所以我发现一个Windows当量(@弗朗索瓦对this question答案)。我安装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”红宝石宝石。但奇怪的是,我仍然有以下错误:

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"' This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension.

 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 

checking for rb_intern3()... yes checking for main() in -llibmysql... yes checking for mysql.h... yes checking for errmsg.h... yes checking for mysqld_error.h... yes creating Makefile

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

warning: ISO C90 forbids mixed declarations and code client.c: In function 'finish_and_mark_inactive': client.c:508:3: warning: ISO C90 forbids mixed declarations and code client.c: In function 'rb_mysql_client_abandon_results': client.c:535:3: warning: ISO C90 forbids mixed declarations and code client.c: In function 'rb_mysql_client_next_result': client.c:938:5: warning: ISO C90 forbids mixed declarations and code compiling mysql2_ext.c compiling result.c result.c: In function 'rb_mysql_result_fetch_fields': result.c:407:35: warning: comparison between signed and unsigned integer express ions linking shared-object mysql2/mysql2.so client.o: In function 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 [email protected]' client.o: In function 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 [email protected]' client.o: In function 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 [email protected]' client.o: In function 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 [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:727: undefined reference to [email protected]' 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: undefined reference to [email protected]' 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/cl ient.c:257: undefined reference to [email protected]' 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/cl ient.c:370: undefined reference to [email protected]' 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/cl ient.c:923: undefined reference to [email protected]' 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/cl ient.c:863: undefined reference to [email protected]' 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: undefined reference to [email protected]' 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: undefined reference to [email protected]' 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: undefined reference to [email protected]' 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: undefined reference to [email protected]' 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: undefined reference to [email protected]' 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 [email protected]' client.o: In function 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 [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:757: undefined reference to [email protected]' 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: undefined reference to [email protected]' client.o: In function finish_and_mark_inactive': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:515: undefined reference to [email protected]' 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: undefined reference to [email protected]' 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 reference to [email protected]' 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/cl ient.c:238: undefined reference to [email protected]' 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: undefined reference to [email protected]' 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 [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:140: undefined reference to [email protected]' 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: undefined reference to [email protected]' 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/cl ient.c:966: undefined reference to [email protected]' 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/cl ient.c:939: undefined reference to [email protected]' 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/cl ient.c:839: undefined reference to [email protected]' 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/cl ient.c:419: undefined reference to [email protected]' 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/cl ient.c:539: undefined reference to [email protected]' 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 [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/cl ient.c:547: undefined reference to [email protected]' 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/cl ient.c:368: undefined reference to [email protected]' 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 reference to [email protected]' 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 reference to [email protected]' 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 [email protected]' client.o: In function 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 [email protected]' result.o: In function 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 [email protected]' result.o: In function 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 [email protected]' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/re sult.c:114: undefined reference to [email protected]' 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: undefined reference to [email protected]' 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: undefined reference to [email protected]' 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: undefined reference to [email protected]' 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: undefined reference to [email protected]' 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 [email protected]' result.o: In function 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 [email protected]' 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: undefined reference to [email protected]' result.o: In function 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 [email protected]' 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: undefined reference to [email protected]' result.o: In function 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 [email protected]' 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: undefined reference to [email protected]' collect2: ld returned 1 exit status make: *** [mysql2.so] Error 1

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

for inspection. Results logged to 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. 

回答

15

我对Win64的环境,同样的错误

我测试了很多的解决方案,但。只为我工作是:

  • 创业板安装mysql2 -v '0.3.11'
+1

谢谢.. !你救了我.. !! – writeToBhuwan

+0

拯救我们! –

+0

谢谢,我正在尝试一切! – Will

9

我一直很恼火通过同样的问题,终于成功安装mysql2。荣誉[email protected]。看起来我通过Google发现的任何其他解决方案都不适用于我。

here复制并粘贴。所以不要信任我。

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"' 

关于我的其他信息。

  • 红宝石1.9.3p392(2013年2月22日)[I386-的mingw32]
  • 滑轨3.2.13
  • MySQL服务器5.6
  • mysql2-0.3.13

PS 即使您成功安装了mysql2,您仍然需要一些工作(例如mysql2.so(LoadError)),并且在我的情况下,它与libmysql有关,并且似乎是mysql2的另一个主要故障。

+0

,我不得不删除LIB的包括选项出于某种原因,因为它是抱怨,它无法找到他们。 .. weird ... 所以对我来说是这样的:gem install mysql2 --platform = ruby​​ - '--with-mysql-dir =“C:\\ connector-6.0.2”' –

-1

  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目录例如:C:\ RailsInstaller \ Ruby1.9.3 \ BIN
  3. 现在重新安装Mysql2宝石
    创业板安装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. 尝试现在都捆绑
2

我在Windows 7 64位上安装。什么工作对我来说是:http://dev.mysql.com/downloads/connector/c/

我把它解压到C:\温度

从下载的C 32位连接器存档。如果您使用不同的目录,请调整下一个命令。

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

疼痛...很多的痛苦。最后工作做:

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

  1. 下载MySQL的连接器C来自http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick
  2. 解压连接器的目录中没有空格的名字!
  3. 将lib/libmysql.dll文件复制到ruby/bin中
  4. gem install mysql2 - --with-mysql-dir = D:\ RoR \ mysql-connector-c(如此给出连接器的目录而不是服务器的目录)

而且我得到了mysql2 v0.3.17和运行...

相关问题