Installing mysql2 gem on Ruby 1.9.2 and Rails 3.0.5 on Windows

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).



5 thoughts on “Installing mysql2 gem on Ruby 1.9.2 and Rails 3.0.5 on Windows”

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=""> <s> <strike> <strong>