3

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

在从sqliteto转换的过程中MySQL,我必须安装 ruby​​ gem mysql2,这在安装时给了我以下错误:

安装 mysql2 时出错:错误:无法构建 gem 原生扩展。

和 都试过了bundle installgem install mysql2但是出现了同样的错误信息。

我知道对许多人都有效的解决方案是sudo apt-get install libmysql-ruby libmysqlclient-dev,但我在Windows上使用 Git Bash ,所以我找到了一个 Windows 等价物(@francois's answer on 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' 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 时出错:错误: 无法构建 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 tomysql_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 tomysql_init@4'client.o:在函数中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 tomysql_ssl_set@24'client.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 tomysql_options@12'c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c 中: 727:未定义对mysql_error@4' client.o: In functionrb_mysql_info' 的引用:c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:267:未定义对mysql_info@4' client.o: In functionrb_mysql_client_warning_count的引用': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:257: 未定义对mysql_warning_count@4' client.o: In functionnogvl_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 functionrb_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 functionnogvl_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 functionnogvl_ping 的引用': c:\ RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:894:未定义对mysql_ping@4' client.o: In functionrb_mysql_client_thread_id' 的引用:c:\RailsInstaller\Ruby1.9.3\ lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:856:未定义对mysql_thread_id@4' client.o: In functionrb_mysql_client_last_id' 的引用:c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\ 1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:825:未定义对mysql_insert_id@4' client.o: In functionnogvl_read_query_result' 的引用:c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\ mysql2-0.3.13\ext\mysql2/client.c:357:未定义的引用mysql_read_query_result@4' client.o: In functionrb_mysql_client_server_info': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.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 tomysql_get_server_info@4' 客户端的引用。 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 tomysql_get_client_version@0' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:757 中:未定义对mysql_get_client_info@0' client.o: In functionrb_mysql_client_real_escape的引用': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:662: 未定义对mysql_real_escape_string@16' client.o: In functionfinish_and_mark_inactive的引用': c:\RailsInstaller \Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:515:未定义的引用mysql_free_result@4' client.o: In functionnogvl_send_query': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:334: 未定义对mysql_send_query@12' client.o: In functionnogvl_close 的引用': c:\ RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:190:未定义对mysql_close@4' client.o: In functionrb_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 functionrb_raise_mysql2_error' 的引用:c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\ 1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.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 tomysql_sqlstate@4' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems 的引用\mysql2-0.3.13\ext\mysql2/client.c:140:未定义的引用mysql_errno@4' client.o: In functionrb_connect': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:297: 未定义引用mysql_errno@4' client.o: In functionrb_mysql_client_store_result': c:\ RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:966:未定义对mysql_errno@4' client.o: In functionrb_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:未定义对mysql_next_result@4' client.o: In functionrb_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 functionrb_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:未定义的引用mysql_errno@4' client.o: In functionrb_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 tomysql_more_results@4' c: \RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:547:未定义对mysql_free_result@4' client.o: In functionnogvl_do_result 的引用:c:\RailsInstaller\Ruby1.9.3 \lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:368: 未定义对mysql_use_result@4' client.o: In functionnogvl_close' 的引用:c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems \1.9.1\gems\mysql2-0.3.13\ext\mysql2/client.c:190:未定义对mysql_close@4' client.o: In functionset_charset_name' 的引用:c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems \mysql2-0.3.13\ext\mysql2/client.c:1067:未定义对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 tomysql_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 tomysql_get_client_info@0' result.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 tomysql_num_rows@4' result.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 tomysql_fetch_field_direct@8' c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13 \ext\mysql2/result.c:114:未定义对mysql_num_fields@4' result.o: In functionrb_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:未定义对mysql_num_fields@4' result.o: In functionnogvl_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 functionrb_mysql_result_free_result' 的引用:c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/result.c:75: 未定义引用mysql_free_result@4' result.o: In functionrb_mysql_result_fetch_row': c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\mysql2-0.3.13\ext\mysql2/result.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 tomysql_num_fields@4' 结果。 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 tomysql_fetch_fields@4'中 result.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 tomysql_free_result@4'中 result.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 tomysql_fetch_fields@4'中 result.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 tomysql_free_result@4'中 result.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 tomysql_num_rows@4'中结果。 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 tomysql_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.
4

5 回答 5

14

我在 Win64 环境中遇到了同样的错误。

我测试了很多解决方案,但唯一对我有用的是:

  • 宝石安装 mysql2 -v '0.3.11'
于 2013-10-15T15:43:47.893 回答
9

I've been so annoyed by the same problem, and finally succeeded in installing mysql2. Kudos to odiszapc@github. It appears any other solution I've found via Google than below doesn't work to me.

Copied and pasted from here. So no credit to me.

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

Additional info on mine.

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

P.S Even if you successfully installed mysql2, you may still need some work (e.g. mysql2.so (LoadError)), and it has something do with libmysql in my case, and seems like yet another major glitch about mysql2.

于 2013-07-27T15:55:04.917 回答
2

我在 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"'
于 2014-03-04T21:37:35.310 回答
0

痛……好痛。最后工作做:

(平台: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...

于 2015-01-02T20:02:01.070 回答
-1

  1. 从http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick下载 Mysql 连接器。
  2. 提取它。复制lib\libmysql.dll文件并将其粘贴到 Ruby 的 bin 目录中,例如: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\include"'
    注意:根据你的更改 mysql 安装路径
  4. 立即尝试捆绑
于 2013-08-20T11:46:02.903 回答