Ruby MySQL adapter on Windows

It is very easy to install Ruby MySQL adapter using gem on Windows.

gem install mysql

But I found Ruby MySQL adapter does not work with MySQL 5.1 on my Windows box. When Ruby executed SQLs or Rails server got requests, I got some errors like this

C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/
connection_adapters/abstract_adapter.rb:39: [BUG] Segmentation fault
ruby 1.8.6 (2009-08-04) [i386-mingw32]

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

It seems the reason is that this version of mysql gem does not work with MySQL 5.1 lib. I saw some suggestions on Web to downgrade MySQL to 5.0 to solve the problem. However, I don’t want to downgrade MySQL. It turns out the solution is very simple. Download MySQL 5.0 noinstall version mysql-noinstall-5.0.89-win32.zip from http://dev.mysql.com/downloads/mysql/5.0.html. Extract libmysql.dll and copy it to C:Rubybin. Then, the problem is solved. I am still running MySQL 5.1. But Ruby uses this MySQL 5.0 version dll.

My environment:  Ruby 1.8.6. Gem 1.3.5. MySQL gem version 2.8.1. Rails version is 2.3.5. Windows XP and MySQL 5.1.

18 thoughts on “Ruby MySQL adapter on Windows

  1. Thanks a million, buddy ! After hours of frustration you gave me the solution that I needed. This worked like a charm. And by the way, I love your blog too. Keep up the good work !
    I took up learning Ruby yesterday as a personal hobby. I would have probably given up without your blog to help me out.

  2. Thank U for your article to help me to deal the same question successful.
    I found your blog with Google when I had being troubled for this problem.
    Secretly tell you when I copy the error message to Google,I barely saw one record.:-)

  3. This post is legen…. wait for it… DARY!!! yes sir this was the fix for the problem running the ruby server with no problems now thanks men

  4. I almost gave up on ROR, thanks to you, i can start learning now!

    Thanks a lot

  5. Wow, you’re awesome! I was almost giving it up after spending lots of time.

    My environment: Ruby 1.8.7, MySQL gem 2.8.1, Rails 2.3.8. Windows XP and MySQL 5.1.

  6. Wow. Would have saved about 3 hours if I had found this sooner. Google bait: windows ruby segmentation fault mysql 5.1

    Thanks again.

  7. Thank you Yun Fu!!! After 5 hours of searching for a workaround, I found your page with luck.

    My environment is ruby 1.9.2, gems 1.3.7, MY SQL server version 5.1.44, on Windows Vista (a.k.a “Diablo”).

    For any others suffering in the same position, may I repeat the error message I received?

    “The application has failed to start because LIBMYSQL.dll was not found.”

    Copying LIBMYSQL.dll to ruby “bin” fails / failed / did / will not work / did not fix or solve the problem.

    As you state above, the problem is an incompatibility issue with ruby and LIBMYSQL.dll for MYSQL 5.1.

    I hope other people will find your page even quicker now. Thanks so much again for posting this valuable information.

  8. correction: incompatibility issue with the mysql GEM for ruby and MYSQL 5.1.

    In my case, I did not get as far as you did. The rails server failed to start and threw the DLL error message.

  9. Tanks very much this worked for me. I just started learning ruby and I couldn’t get my first script using mysql to work, this was very frustrating.

    Windows 7, MySQL 5.1.41, ruby 1.9.2, gems 1.3.7

  10. Hi, thanks…

    unfortunately the file ‘mysql-noinstall-5.0.89-win32.zip’ is NO MORE AVAILABLE on the web site indicated (there aren’t any mirrors…)

    Can you suggest me how I can have the file ‘libmysql.dll’ for mysql 5.0?