Installing mysql2 gem on Ruby 1.9.2 and Rails 3.0.5 on Windows

December 22, 2011 · Posted in Development 

When running ‘rake db:create’, you may get the following error:

>rake db:create
rake aborted!
126: The specified module could not be found. - d:/RailsInstaller/Ruby1.9.2/li

or may get these errors while installing mysql:

rake aborted !
uninitialized constant mysql2

Error ‘uninitialized constant mysql2′ comes when mysql2 installation is not done properly.

To solve this issue and successfully install mysql2 gem, follow these steps:

Install DevKit

1. Download and install DevKit


2. Run this command in DevKit folder :

ruby dk.rb init

3. Edit the generated config.yml file as per your system available Rubies version if required

- c:/RailsInstaller/Ruby1.9.2

4. Run in the DevKit folder:

ruby dk.rb install

You have successfully installed the DevKit.


Install MySql2 gem

5. Download mysql-connector from

and unzip it to folder c:\rubyinstaller\mysql

6. Run gem install myql2 with the following parameters:

gem install mysql2 --platform=ruby -- '--with-mysql-dir="c:/RailsInstaller/mysql"'


if it doesn’t work, try with these options:

gem install mysql2 -- '--with-mysql-lib="c:/RailsInstaller/mysql/lib" --with-mysql-include="c:/RailsInstaller/mysql/include"'


7. Copy libmysql.dll from c:\RailsInstaller\mysql\lib to bin/ folder of Ruby 1.9.2 (for example, c:\ruby192\bin)


You are done with installation of Mysql2 gem on Ruby 1.9.2 and Rails 3.0.5 on Windows.


Now you can use mysql in your Rails project

8. Add mysql2 gem to the file ‘Gemfile’ in your project folder

gem 'mysql2'

9. Edit config/database.yml file
adapter: mysql2
encoding: utf8
database: mydbname
pool: 5
username: root
socket: /tmp/mysql.sock

Specify your login (usually, root in Windows) and password (usually, blank in Windows).




  • Ernests Dreimanis

    thanks this was helpfull !

  • Jose Juan Lagunas


    Muchas gracias (y)

  • Leo sandoval

    hey tnks.
    I would not have done it without your help

  • Dimitris Klimis

    Hey man, thanks for the great guide. Have been installing rails for 2 years now and always come back to this. I think there is a type in the gem installation. –with-mysql-lib=”c:/RailsInstaller/mysql/bin should be /lib. Cheers!

  • Anonymous

    thanks! I fixed it and added another option of installation mysql2.