Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
C:\Users\Luis>ruby -v
ruby 1.9.2p0 (2010-08-18) [i386-mingw32]
C:\Users\Luis>gem install mysql2 --platform=ruby -- --with-mysql-include=C:\mysql-5.1.51-win32\include --with-mysql-lib=C:\mysql-5.1.51-win32\lib\opt
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
Successfully installed mysql2-0.2.5
1 gem installed
irb(main):001:0> require 'mysql2'
=> true
irb(main):002:0> client = => "localhost", :username => "root", :database => 'foo_dev')
irb(main):003:0> results = client.query("SELECT COUNT(id) FROM users")
=> #<Mysql2::Result:0x2bd9148>
irb(main):004:0> { |r| r }
=> [{"COUNT(id)"=>0}]

ghost commented May 22, 2011

Hi Luis,
I'm not getting this mysql2 to build properly. I'm running Ruby 1.9.2, and Rails 3.0.7. I managed to get the sqlite3 gem built, but I'm getting the 'mysql.h missing' error. I changed your 'gem install' to properly point to \lib, instead of \lib\opt, as there is no \lib\opt in the MySQL 5.5 install directory structure. Any ideas? Is this problem reintroduced by MySQL 5.5?


luislavena commented May 22, 2011

Can you please follow the instructions here?

Download the 32bits version of MySQL Connector/C.


ghost commented May 24, 2011


luislavena commented Jul 8, 2011

For those interested in a complete guide to MySQL installation on Windows, I wrote an article on my blog:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment