How to Install Mysql2 Ruby Gem on Windows

If you are getting an error like the following, when running ‘bundle install’ or ‘gem install mysql2′ on Rails 3:

gem install mysql2
ERROR: Error installing mysql2:
The ‘mysql2′ native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from ‘http://rubyinstaller.org/downloads’ and follow the instructions
at ‘http://github.com/oneclick/rubyinstaller/wiki/Development-Kit’

Then read on.

From Rails v3 onwards, mysql2 has been made the default mysql gem/driver for MySql. That’s good news, as mysql2 is offering better performance over the other gem (mysql). For Windows users, however, installing mysql2 gem is going to be tricky.

Make sure you have Ruby 1.9.2, Rails 3.0.7 or greater, and you have updated your gems.

After searching around for a way to make it work, I got it installed with the following on the command prompt:

gem install mysql2 -v 0.2.6

With the following results:

Fetching: mysql2-0.2.6-x86-mingw32.gem (100%)
Successfully installed mysql2-0.2.6-x86-minw32
1 gem installed
Installing ri documentation for mysql2-0.2.6-x86-mingw32…
Enclosing class/module ‘mMysql2′ for class Client not known
Installing RDoc documentation for mysql2-0.2.6-x86-mingw32…
Enclosing class/module ‘mMysql2′ for class Client not known

Try it. Let me know your results in the comments.


Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>