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!