Installing mysql gem on Win7 x64 for MySQL 5.1.x


G

Geoff Rowell

As of the time this was written, I'm running:

* Windows 7 x64
* mysql Ver 14.14 Distrib 5.1.48, for Win64 (unknown)
* ruby 1.8.7 (2010-06-23 patchlevel 299) [i386-mingw32]
* gem 1.3.7

This setup presents a particular problem, because the mysql gem is at
version 2.8.1. That expects to run against a 32-bit version of MySQL
5.0.x. It also doesn't contain the proper ri/rdoc components.

Originally, when I tried to install the mysql gem, I ended up with the
Cygwin (mingw32) version of the gem and a whole mess of documentation
warnings. That's not what I wanted! I think this may be because I'm
running an x64 OS, so it can't find a matching platform.

Here's what I had to do to get it working:

1. Install the mysql Gem
========================
Here's the lengthy command line I ended up using:

---
C:\>gem install --no-rdoc --no-ri mysql --platform=x86-mswin32 --
--with-mysql-dir="C:\Program Files\MySQL\MySQL Server 5.1\my.ini"
Successfully installed mysql-2.8.1-x86-mswin32
1 gem installed

C:\>
---

The options after the standalone double-dashes are passed to the
installer of the gem. Strangely enough, the "--with-mysql-dir" option
seems to work when passed the full path name of my database
configuration file.

The "--no-rdoc" and "--no-ri" options tell gem to skip building
documentation.

The "--platform=x86-mswin32" option forces gem to install the version
for the 32-bit Windows platform.

Once I managed to install the mysql gem, I was still seeing this error
from rake (part of Rails):

---
W:\cardcatalog>rake db:create:all
(in W:/cardcatalog)
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please
install
the mysql gem and try again: gem install mysql.
rake aborted!
193: %1 is not a valid Win32 application. -
C:/Ruby187/lib/ruby/gems/1.8/gems/
mysql-2.8.1-x86-mswin32/lib/1.8/mysql_api.so

(See full trace by running task with --trace)

W:\cardcatalog>
---

Obviously, that error message is a total red herring.

2. Install a Matching MySQL DLL
===============================
Now that the proper gem is installed, it needs a MySQL DLL that matches
the interfaces it was built for.

---
MySql Version of Gem

You can figure out which version the gem was built against by looking in
the file, "History.txt", in the install location of the gem. In my case,
it was located here:

* C:\Ruby187\lib\ruby\gems\1.8\gems\mysql-2.8.1-x86-mswin32\History.txt
---

Since I'm running a 64-bit version of MySQL 5.1, I ended up downloading
the latest "no installer" ZIP file for the 32-bit version of MySQL 5.0.

* mysql-noinstall-5.0.91-win32.zip

If you look inside, you'll find "libmysql.dll" in the "bin" directory.
You need to copy this into the "bin" directory of your Ruby
installation.

Once this is done, you'll find that Ruby is able to talk to the MySQL
database server.
 
Ad

Advertisements

L

Luis Lavena

As of the time this was written, I'm running:

* Windows 7 x64
* mysql Ver 14.14 Distrib 5.1.48, for Win64 (unknown)
* ruby 1.8.7 (2010-06-23 patchlevel 299) [i386-mingw32]
* gem 1.3.7

This setup presents a particular problem, because the mysql gem is at
version 2.8.1. That expects to run against a 32-bit version of MySQL
5.0.x. It also doesn't contain the proper ri/rdoc components.

Originally, when I tried to install the mysql gem, I ended up with the
Cygwin (mingw32) version of the gem and a whole mess of documentation
warnings. That's not what I wanted! I think this may be because I'm
running an x64 OS, so it can't find a matching platform.

No, cygwin != mingw32

Second, you got documentation warnings due old RDoc and missing
documentation of mysql gem.

Ruby is 32bits, you can't use DLLs that are 64bits, that includes
MySQL.

You need a 32bits DLL, and more precisely, due MySQL ABI changes, the
exact same version used to build the binary gem: 5.0.83
Here's what I had to do to get it working:

1. Install the mysql Gem
========================
Here's the lengthy command line I ended up using:

---
C:\>gem install --no-rdoc --no-ri mysql --platform=x86-mswin32 --
--with-mysql-dir="C:\Program Files\MySQL\MySQL Server 5.1\my.ini"
Successfully installed mysql-2.8.1-x86-mswin32
1 gem installed

If you're using Ruby mingw32 version, I would not recommend install
mswin32, is the same gem.

The command you provided is wrong and do not do what you intend to.
Since I'm running a 64-bit version of MySQL 5.1, I ended up downloading
the latest "no installer" ZIP file for the 32-bit version of MySQL 5.0.

* mysql-noinstall-5.0.91-win32.zip

If you look inside, you'll find "libmysql.dll" in the "bin" directory.
You need to copy this into the "bin" directory of your Ruby
installation.

Once this is done, you'll find that Ruby is able to talk to the MySQL
database server.

You can find this and more accurate details in the RubyInstaller wiki
tutorials:

http://wiki.github.com/oneclick/rubyinstaller/tutorials
 
G

Geoff Rowell

Luis said:
No, cygwin != mingw32

Second, you got documentation warnings due old RDoc and missing
documentation of mysql gem.

Ruby is 32bits, you can't use DLLs that are 64bits, that includes
MySQL.

You need a 32bits DLL, and more precisely, due MySQL ABI changes, the
exact same version used to build the binary gem: 5.0.83


If you're using Ruby mingw32 version, I would not recommend install
mswin32, is the same gem.

The command you provided is wrong and do not do what you intend to.


You can find this and more accurate details in the RubyInstaller wiki
tutorials:

http://wiki.github.com/oneclick/rubyinstaller/tutorials

Okay. The "mingw32" platform isn't intended for Cygwin. However, I think
you're focusing on a minor detail and missing these key points:

1. You need to specify the "x86-mswin32" platform when loading the gem
on a 64-bit Win7 system running the mswin32 flavor of Ruby.

2. Getting the gem to install is only half the battle. You still need to
get a copy of the DLL that matches the gem. These directions allow you
to run a later version of MySQL than the one used to build the gem.

3. Despite spending some serious time looking into this problem, I was
unable to find all of this information organized in one location. I felt
that this forum was a logical place to look for this information.

I'm just trying to ease the way of some other poor soul running into
this problem.

-Geoff
 
L

Luis Lavena

Okay. The "mingw32" platform isn't intended for Cygwin. However, I think
you're focusing on a minor detail and missing these key points:

1. You need to specify the "x86-mswin32" platform when loading the gem
on a 64-bit Win7 system running the mswin32 flavor of Ruby.

Unless you installed a 64bits version of ruby, that is the only way.

Ruby 32bits (from garbagecollect) install gems with x86-mswin32-60
platform

RubyInstaller (from rubyintaller.org) install gems with x86-mingw32.
2. Getting the gem to install is only half the battle. You still need to
get a copy of the DLL that matches the gem. These directions allow you
to run a later version of MySQL than the one used to build the gem.

I don't understand the battle about the gem installation, you don't
need to provide any options to it, it just install the binary.

Of course you still depend on a working MySQL installation, and the
libmysql.dll available in the system and accessible to Ruby.
3. Despite spending some serious time looking into this problem, I was
unable to find all of this information organized in one location. I felt
that this forum was a logical place to look for this information.

I think a wiki page, like the one I have mentioned fits better. Also,
there are 2 or 3 tutorials in that page that provide instructions on
how to install it and even more, how to compile the gem to a different
version of the gem.

Things in the forum (actually a mailing list) get lost with time and
people will still ask again. Is more easy point to a always persistent
link (wiki).
I'm just trying to ease the way of some other poor soul running into
this problem.

Understood, but still, the instructions are not accurate and your
indications add more noise to the problem.

Sometimes I see people suffering that Ruby is complicated on Windows
and most of the time is associated with the instructions they are
following.
 
L

Luis Lavena

Unless you installed a 64bits version of ruby, that is the only way.

Ruby 32bits (from garbagecollect) install gems with x86-mswin32-60
platform

RubyInstaller (from rubyintaller.org) install gems with x86-mingw32.

Just to make it more clear:

gem install mysql will install the correct binary version, and if none
is found, will install the 'ruby' version which will trigger the
compile process.
 
Ad

Advertisements

Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top