Using mysql2 on Windows

Another edition of Sara uses Rails on Windows! *muppety fanfare*

Trying to get mysql2 to run on Windows is a bit of a pain. I used the lovely installer from and then created an app with :

rails new testapp -d mysql

and then bundled.

By default this installs the mysql2 gem. There are some gotchas, and hopefully this will help:

  1. You have to install mysql first (derp!). Go here and pick either the 32 or 64 bit MSI installer, and use this guide to pick your options during the install (section II). I know, it’s an old guide, but it works fine. And it has pictures!
  2. You may get this error: “%1 is not a valid Win32 application.” This means you need to go here and get libmysql.dll, and copy it into c:\RailsInstaller\Ruby1.8.7\bin. Get the right version or your migrations will fail when you try to add indexes – the MySQL 5.5.9 64-bit version of libmysql.dll will NOT work! I got this version and it worked just fine: (you don’t need the MSI installer for this one, just grab a zippy file).
  3. Next error you may get is “rbreadline.rb:4404: uninitialized constant RbReadline::Encoding (NameError)”. Thanks to this blog post I found the answer is to go into c:\RailsInstaller\Ruby1.8.7\lib\ruby\site_ruby\1.8\rbreadline.rb, and comment out line 4404.

There you go! Rake away!


  1. oscar frias

    hey i just want to say thank you ALOT with this bit of info i got mysql connected!

    Thanks again!!

  2. Installing mysql2 on Windows is really a tricky issue because of various configurations, 32 bit and 64 bit issues.

    You can successfully install mysql2 by following the details given on – “”

  3. Marc Seifert

    thanks a dozen for this info! you helped me run mysql2 properly.. had the %1 problem and just followed your instructions. much respect! and i appreciate the share :) thankss!

Leave a Reply

Your email address will not be published. Required fields are marked *