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:
- 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.
- 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.