1

我想更多地使用 Ruby,目前似乎掌握了 sinatra,但现在也想从关系数据库中提取数据。我倾向于将 Mysql 用于测试应用程序并尝试安装 gem,但是当它尝试编译它所依赖的本机 do_mysql gem 时,我不断收到异常。

我确实安装了本机扩展,并且它们对 JSON gem 运行良好,我记得不久前在某处读到 do_mysql 目前不支持 windows,所以只是想知道是否仍然如此。

在 Windows 7 上使用 ruby​​ 1.9.2(通过 ruby​​ 安装程序 + 本机扩展安装)

这是有帮助的例外情况:

C:\dump\ruby\DataMapperTest\gems>gem install dm-mysql-adapter-1.2.0.gem
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing dm-mysql-adapter-1.2.0.gem:
        ERROR: Failed to build gem native extension.

        C:/Tools/Ruby192/bin/ruby.exe extconf.rb
checking for my_global.h... no
checking for mysql.h... no
checking for main() in -llibmysql... no
checking for mysql_query() in mysql.h... no
checking for mysql_ssl_set() in mysql.h... no
checking for localtime_r()... no
checking for gmtime_r()... no
checking for mysql.h... no
checking for MYSQL_TYPE_STRING in mysql.h... no
checking for MYSQL_TYPE_BIT in mysql.h... no
checking for MYSQL_TYPE_NEWDECIMAL in mysql.h... no
checking for mysql_query() in mysql.h... no
checking for mysql_ssl_set() in mysql.h... no
checking for mysql_sqlstate() in mysql.h... no
checking for mysql_get_ssl_cipher() in mysql.h... no
checking for mysql_set_character_set() in mysql.h... no
checking for mysql_get_server_version() in mysql.h... no
checking for MYSQL_FIELD.charsetnr in mysql.h... no
creating Makefile

make
C:/Tools/Ruby192/bin/ruby -e "puts 'EXPORTS', 'Init_do_mysql'"  > do_mysql-i386-
mingw32.def
gcc -I. -IC:/Tools/Ruby192/include/ruby-1.9.1/i386-mingw32 -I/C/Tools/Ruby192/in
clude/ruby-1.9.1/ruby/backward -I/C/Tools/Ruby192/include/ruby-1.9.1 -I.   -O3 -
g -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings
 -Wno-missing-field-initializers -Wno-long-long -Wall   -o do_common.o -c do_com
mon.c
gcc -I. -IC:/Tools/Ruby192/include/ruby-1.9.1/i386-mingw32 -I/C/Tools/Ruby192/in
clude/ruby-1.9.1/ruby/backward -I/C/Tools/Ruby192/include/ruby-1.9.1 -I.   -O3 -
g -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings
 -Wno-missing-field-initializers -Wno-long-long -Wall   -o do_mysql.o -c do_mysq
l.c
do_mysql.c:5:19: fatal error: mysql.h: No such file or directory
compilation terminated.
make: *** [do_mysql.o] Error 1


Gem files will remain installed in C:/Tools/Ruby192/lib/ruby/gems/1.9.1/gems/do_
mysql-0.10.7 for inspection.
Results logged to C:/Tools/Ruby192/lib/ruby/gems/1.9.1/gems/do_mysql-0.10.7/ext/
do_mysql/gem_make.out

C:\dump\ruby\DataMapperTest\gems>

Mysql 5.5社区版安装配置完毕,Mysql已添加到系统PATH中。

4

2 回答 2

3

DataMapper 和 DataObjects(连接到 DB 的较低层)在 Windows 上工作

但是,似乎 do_mysql 0.10.7 缺少x86-mingw32平台的预编译二进制文件:

http://rubygems.org/gems/do_mysql/versions

您可以使用 MySQL Connector/C 接口自己编译 do_mysql,该接口与您计算机中安装的 MySQL 版本无关。

请查看此博客文章,其中提供了安装说明:

http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/

这些说明适用于mysqlgem,但将其更改为do_mysql应该可以工作(除了特定于 MySQL 的示例代码。

希望有帮助。

于 2011-11-17T17:38:30.387 回答
0

为了取消 Luis 的回答,它看起来像这样:

gem install do_mysql --platform=ruby --with-mysql-dir="C:/PROGRA~1/MySQL/MYSQLS~1.7/"

其中“mysql-dir”路径是 x64 系统上“C:\Program Files”中“MySQL Server 5.7”目录的简短版本。

于 2016-06-07T03:50:28.530 回答