Installing ruby 1.9.2p0 and Rails 3.0.3 and getting it to work with MySQL on Windows

Installing ruby 1.9.2 on Windows took several false starts before I got on the right track.

My development machine is a dual-boot Windows and Linux monster with pre-existing versions of Ruby, Rubygems, Rails, and MySQL. On the Windows side, I have a working version using ruby 1.86, rubygems 1.3.5, rails 2.3.8, and MySQL 5.1. The oldest version of ruby was sitting in C:\ruby\bin, with newer versions in subdirectories like C:\ruby\1.9.2-rc2. I get some warning messages because the ruby version is older than the rubygems and rails, but the bottom line is the programs work. So, writing over a working version of ruby or MySQL was not an option.

The rvm gem is not available on Windows, so to switch ruby versions I run a batch script that prepends the desired ruby bin to the path. I tried to install ruby version 1.9.2-p0 in the same way that I had 1.8.7, but got flaky errors. For whatever reason, the 1.9.2 ruby version had the 1.8 gems on the path. This meant that I could install gems on 1.9.2, and gem list would report the new gems, but programs used gems from 1.8. This was not good. I finally installed ruby 1.9.2 in a directory that was not a subdirectory of C:\ruby, made sure the path had only one ruby entry, etc. Finally I chose to regedit and revise any references to ruby 1.8 executables to ruby 1.9.2. Now ruby 1.9.2 programs were using the gems I had installed. But programs using MySQL still didn’t run.

One error I frequently (but not always) saw was segmentation fault. Luis Lavena says that is always a MySQL dll issue. He was right. Luis Lavena is the expert on ruby and Windows. He said that you need to run MySQL 5.0, as the ruby bindings use that version of libmysql.dll. Plus, the documentation on the web references the mysql gem but not the mysql2 gem. Luis Lavena is correct, but incomplete.

First, the mysql2 gem now works on Windows with ruby 1.9.2, and the rails s command expects the mysql2 gem if you specified -d mysql when creating your rails project. The solution was to have the libmysql.dll from MySQL 5.0.89 as the first/only libmysql.dll in the path. But you don’t need to install an old version of MySQL to do this. The best solution is on Download, which can currently be found at, and extract only libmysql.dll from there, using your favorite unzip program (mine is 7-Zip). Then, place libmysql.dll in your path. I have it in my ruby bin; your path may differ.

To complete the solution, I’ve taken both my ruby bin and MySQL Server 5.1\bin off my default path and added two batch files to add one or the other back in. There is a ruby gem patheditor that you may want to try out, but of course it requires that ruby be in your path.

Addendum: April 6, 2011 With the latest versions of Rails (3.0.5) and the mysql2 gem (0.2.6 and 0.2.7), you need to use the MySQL 5.1 version of libmysql.dll instead of the MySQL 5.0.89 version. Either have the MySQL 5.1 bin in your path or a copy of the MySQL 5.1 version of libmysql.dll somewhere in your path.

Leave a Reply




You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>