TMTOWTDI – mysql2 and Windows edition

May 26th, 2011  |  Published in ruby

So, you’re trying to get Rails going on Windows, and you’ve used the handy package at, installed the equally handy Ruby DevKit, and now all you need to do is install the mysql2 gem to get going.

At this point, if you do what any normal person might think to do, which is gem install mysql2, you’ll fail because the gem wants a bunch of MySQL dev headers. That’s not a bad thing … we live in a world of dependencies that must be met.

One answer you can pursue is to download the big MySQL archive and pass a few flags along when you install the gem:

gem install mysql2 -- --with-mysql-lib="c:\Program Files\mysql\lib" --with-mysql-include="c:\Program Files\mysql\include"

Then be ready to tell Bundle the same thing for your Rails app proper, which I couldn’t get working.

What also works, and is much more simple, is just getting the version that works with Mingw32 build environments (which is what you get when you install the DevKit):

gem install mysql2 --version 0.2.6

Bundle file?

gem 'mysql2', '0.2.6'

then bundle install

This is all, by the way, another lovely use case for VMWare: Freeze dry a VM at the point before you start desperately following whatever random advice you can find from people trying to make some portion of Ruby or Rails work on Windows so once you think you have it figured out you can roll back to a pristine state and make sure it all works before you document.

Leave a Response

© Michael Hall, licensed under a Creative Commons Attribution-ShareAlike 3.0 United States license.