1

I am wanting to play some more with Ruby and currently seem to have a grasp of sinatra, but would also like to now pull in data from a relational database. I tend to use Mysql for test apps and tried installing the gems but I keep getting an exception when it tries to compile the native do_mysql gem which it is reliant upon.

I do have the native extensions installed and they worked fine for the JSON gem, I remember reading somewhere a while back that the do_mysql wasnt supported for windows currently, so was just wondering if this is still the case.

Using ruby 1.9.2 on windows 7 (installed via ruby installer + native extensions)

Here is the exception incase it helps:

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 community edition is installed and configured and Mysql has been added to the system PATH.

Grofit
  • 17,693
  • 24
  • 96
  • 176

2 Answers2

3

DataMapper and DataObjects (the lower layer that connects to the DB) do works on Windows.

However, seems that do_mysql 0.10.7 is missing the precompiled binary for x86-mingw32 platform:

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

You can compile do_mysql yourself using MySQL Connector/C interface, which is independent of the version of MySQL you have installed in your computer.

Please take a look to this blog post which provides installation instructions:

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

The instructions are for mysql gem, but changing it to do_mysql should work (except for the example code which is MySQL specific.

Hope that helps.

Luis Lavena
  • 10,348
  • 1
  • 37
  • 39
  • Worked a treat, and I learned something new. Thanks alot for taking the time to help! one thing that did throw me though was when I was specifying the MySQL directory on the command line I was trying to use a relative path, and was causing errors, making it absolute fixed it (I know the example you show has it absolute but didnt know that was a requirement), just incase that trips up anyone else. – Grofit Nov 18 '11 at 09:35
  • Awesome, will update the instructions to mention that and also avoid path with spaces! :) – Luis Lavena Nov 18 '11 at 15:30
0

to delinkify Luis' answer, it looks something like this:

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

where the "mysql-dir" path is the short version of the "MySQL Server 5.7" directory in "C:\Program Files" on a x64 system.

Drew Delano
  • 1,421
  • 16
  • 21