Ruby 1.8.x and MySQL Issues on Win32

When installing Ruby, the MySql gem and a version of MySQL database watch out for the problems you may hit in terms of failed runtime dependencies. This issue has manifested itself a couple of times on different machines and is a pain.


I recently installed Ruby 1.8.6 with the one-click-installer, reported as ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] when using C:\> ruby -v. I also installed fresh versions of all the gems I’ve used up to this point, including the latest mysql gem at version 2.7.3. I then re-installed MYSQL at version 5.0.45-community-nt MySQL Community Edition (GPL) and started to re-test my code – this all worked out fine.


In parallel a colleague performed identical installations apart from taking a later version of MySQL (candidate release 5.1). He hit problems, reported at runtime, as segmentation faults and strange errors referencing each_hash and other arbitrary methods.


It’s worth noting that Ruby relies upon the mysql gem to provide wrappers for win32 binary shared objects (DLL’s) located in the MySQL database installation directory. First thing you need to verify is that the environment search path includes explicit reference to the MySQL binary folder, in my case c:\program files\MySQL\MySQL Server 5.0\bin. The Ruby mysql gem uses a Ruby shared object ( to wrap a win32 DLL libmysql.dll found in the MySQL Server 5.0\bin folder and we pinpointed this as the root cause of the problem (don’t know why though!).


For some reason the version of libmysql.dll in MySQL 5.1 falls-over where the version in the 5.0.45 installer is ok. We replaced his later DLL version (5.1) with the one from my installation (5.0.45) and all worked well. 


This problem also hit me with my original MySQL installation some months ago albeit with different symptoms  – where I had to introduce a new LIBMYSQL.DLL from the web and replace the one in my bin directory.


Not sure if there’s an official line on this but haven’t managed to locate any real meaningful explanation so if you are beset by strange Ruby/MySQL failures, try replacing the LIBMYSQL.DLL with an older/newer version.


2 Responses to Ruby 1.8.x and MySQL Issues on Win32

  1. Dr1 says:

    You have saved the grim outlook of my Rails project with this post. I got totally random segfaults all over the place and now I found out it was because of MySQL ! Only investigated the problem by googling the NoMethodError <#MySQL bla ! Thank you a million times, even if this post is relatively old 😀

  2. […] matter what I tried the script always breaks. After a long time looking for it, I found this blog wrote on […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: