Ruby, MySQL on WinXP?

Hello All,

I'm just starting out learning Ruby, having come from a PHP background.

I've downloaded the latest stable Ruby release, and have also used the
GEM package manager to install Rails, but I'm a little confused about
how I connect Ruby to MySQL?

The only references I can find to a Ruby driver for MySQL call for
compiling, and I (and many other WinXP users, I imagine) don't have a
copy of Visual C++ with which to do that.

Is there no official supported driver for connecting Ruby to MySQL
under Windows?

Forgive the newbiness of the question, but it's been bugging me since I
installed Ruby, and given my PHP background, I sort of take being able
to connect to MySQL for granted.

Many thanks for any help!

Much warmth,

planetthoughtful

planetthoughtful wrote:

Hello All,

I'm just starting out learning Ruby, having come from a PHP background.

I've downloaded the latest stable Ruby release, and have also used the
GEM package manager to install Rails, but I'm a little confused about
how I connect Ruby to MySQL?

The only references I can find to a Ruby driver for MySQL call for
compiling, and I (and many other WinXP users, I imagine) don't have a
copy of Visual C++ with which to do that.

Is there no official supported driver for connecting Ruby to MySQL
under Windows?

There is a pure-Ruby MySQL driver.

http://raa.ruby-lang.org/project/ruby-mysql/

might be it.

James

···

--

http://www.ruby-doc.org - Ruby Help & Documentation
Ruby Code & Style - Ruby Code & Style: Writers wanted
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
http://www.30secondrule.com - Building Better Tools

I wrote a (breif!) tutorial for getting MySQL running via DBI on Windows 2000/XP

It is actually a Ruport tutorial, but everything but the last step is
just getting DBI/MySQL running:

http://stonecode.org:2501/stonecodeproductions/published/Ruport%2C+MySQL+and+Windows

···

On 11/30/05, planetthoughtful <planetthoughtful@gmail.com> wrote:

Is there no official supported driver for connecting Ruby to MySQL
under Windows?

planetthoughtful wrote:

... and I (and many other WinXP users, I imagine) don't have a
copy of Visual C++

Microsoft offers a free C++ compiler .....

Some instructions for use .....

I don't think the toolkit comes with "nmake" though, so you're out of
luck w.r.t. executing a make file. You can either try to find someone
with nmake.exe to give you (illegally, I guess) or you can
hand-translate a makefile into a series of steps you can call from a
script.

Hi James,

Thank you -- have it working now!

Much warmth,

planetthoughtful

planetthoughtful wrote:

Hello All,

I'm just starting out learning Ruby, having come from a PHP background.

I've downloaded the latest stable Ruby release, and have also used the
GEM package manager to install Rails, but I'm a little confused about
how I connect Ruby to MySQL?

The only references I can find to a Ruby driver for MySQL call for
compiling, and I (and many other WinXP users, I imagine) don't have a
copy of Visual C++ with which to do that.

Is there no official supported driver for connecting Ruby to MySQL
under Windows?

You're right there's no "official supported driver".

James Britt offered:

There is a pure-Ruby MySQL driver.
http://raa.ruby-lang.org/project/ruby-mysql/
might be it.

That is indeed the pure-Ruby MySQL driver. I think I've heard it doesn't
work with MySQL 5.

There are two other ways to connect to MySQL. One is to use the MySQL ODBC
driver (available from mysql.com) along with Ruby-DBI.

Another involves compiling MySQL, or at least finding a pre-compiled binary
that works with your version of MySQL. I don't know why they're so hard to
find at the moment. But at least you don't need to fork out for Visual
Studio to compile it: check out the following page for info on the tools you
need and how it's only half a gig of downloading:

The Instant Rails project is currently using the pure-Ruby driver, but watch
for when they move to a binary, potentially with MySQL 5. (And MySQL 5 seems
to be a real DBMS.)

Other options (ones that I prefer over MySQL at the moment) are:
* MS SQL Server (limited storage and memory Express Edition available free
here:
  http://www.microsoft.com/sql/downloads/trial-software.mspx#EEAA\)
* SQLite (columns are untyped; available from http://sqlite.org)

Please report back when successful, to help others like yourself.

Cheers,
Dave

You can just use MinGW.
http://www.mingw.org/

this gives you gcc and make.

···

On 11/30/05, Tree Dweller <x@versatechs.com> wrote:

I don't think the toolkit comes with "nmake" though, so you're out of
luck w.r.t. executing a make file. You can either try to find someone
with nmake.exe to give you (illegally, I guess) or you can
hand-translate a makefile into a series of steps you can call from a
script.

- gcc works fine

- you don't need nmake: dsw2mak will convert MS project files to make files
  gawk -f /usr/local/bin/dsw2mak *.dsw

- you don't have to recompile mysql in its entirety, just the client library

- many of the mysql .h defaults have to be tweaked to work on Windows. Specifically, files:
  my_config.h
  my_global.h

- a native mysql driver that links to the libmysqlclient.a file can be found at,
  http://www.tmtm.org/en/mysql/ruby/

- if you have never compiled a C pgm before, I wouldn't recommend trying this

Tree Dweller wrote:

···

planetthoughtful wrote:

... and I (and many other WinXP users, I imagine) don't have a
copy of Visual C++

Microsoft offers a free C++ compiler .....
http://msdn.microsoft.com/visualc/vctoolkit2003/

Some instructions for use .....
Technical documentation | Microsoft Learn

I don't think the toolkit comes with "nmake" though, so you're out of
luck w.r.t. executing a make file. You can either try to find someone
with nmake.exe to give you (illegally, I guess) or you can
hand-translate a makefile into a series of steps you can call from a
script.

Tree Dweller wrote:

I don't think the toolkit comes with "nmake" though, so you're out of
luck w.r.t. executing a make file.

I think either the Platform SDK (downloadable) does, and you need that to compile most anything on Windows anyway, or the .NET SDK does. Unfortunately both hefty downloads, and require some tweaking to get to work right.

The main problem with the downloadable toolkit is that it doesn't come with the import libraries to MSVCRT.DLL, which means most builds will fail to link. The .NET SDK comes with them, but:

- the CL.EXE that comes with .NET v1.1 is a crippled version that doesn't do optimizations.
- the one that comes with v2.0 is a complete compiler, but the import libraries link against the new MSVCRT80.DLL, which is not provided with the SDK download or anywhere else legally.

If doing Rails development, just abuse that you are provided a database layer - use SQLite3 for development, works as a charm without running the server, and use MySQL as the production server. Before deploying, use Rails Schemas to dump the development DB metadata and recreate it from scratch in the production environment. The production machine will most likely be a *nix server where the native extensions are either less painful to build, or Someone Else's Problem.

Oh - and Cygwin helps loads too.

David Vallner

Hi Dave,

I am actually connecting without difficulty (so far?) to MySQL 5.0.16
from Ruby using the ruby-mysql package downloaded from the link in
James' message. I'm not sure if ruby-mysql supports the new features in
MySQL 5 (ie Stored Procedures, Views etc), but certainly it works with
SELECTs, and I can't see why it wouldn't work with INSERTs and UPDATEs.

The only additional step required at MySQL's end is to ensure that
you're using the OLD_PASSWORD protocol for the user you define for
connecting from Ruby.

For more info, see:
http://dev.mysql.com/doc/refman/5.0/en/old-client.html

Much warmth and many thanks,

planetthoughtful

Still, I'm kind of curious as to why Ruby doesn't have an officially
supported MySQL driver (or, is it just that it doesn't have one for
Windows)?

It's the first thing a PHP coder hoping to learn Ruby would reach for,
and it's a little disconcerting that one isn't provided in the GEM
package manager...

I'm not criticising Ruby, it just strikes me as odd.

Thanks to everyone who helped!

Much warmth,

planetthoughtful

I'm using it on Windows, its all bundled to gether in Instant Rails:

  http://instantrails.rubyforge.org/

Curt

···

On 12/1/05, planetthoughtful <planetthoughtful@gmail.com> wrote:

Still, I'm kind of curious as to why Ruby doesn't have an officially
supported MySQL driver (or, is it just that it doesn't have one for
Windows)?

It's the first thing a PHP coder hoping to learn Ruby would reach for,
and it's a little disconcerting that one isn't provided in the GEM
package manager...

I'm not criticising Ruby, it just strikes me as odd.

Thanks to everyone who helped!

Much warmth,

planetthoughtful

MySql now has a Ruby section in the forums area.

http://forums.mysql.com/list.php?116