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
b/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/1.9/mysql2.so

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

fromĀ http://rubyinstaller.org/downloads/

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

http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick

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
development:
adapter: mysql2
encoding: utf8
database: mydbname
pool: 5
username: root
password:
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>