sboland926 sboland926 - 5 months ago 28
MySQL Question

Rails Server causes error with Mysql2

I am running Rails 3.2 and Ruby 2.0 on a Windows 7 machine.
I finally got Mysql2 installed (at least I thought so). I can run "bundle install" with no problem, and mysql2 v.0.3.16 shows up in my gem bundle.

But when I run "gem install mysql2" it fails due to native extensions.
Now I am trying to run "rails s" to start my server, and I am getting more errors.

Stealth@STEALTH-PC ~/Documents/GitHub/flitti (tony-dev)
$ rails s
DL is deprecated, please use Fiddle
:8:in `require': cannot load such file -- mysql2/mysql2 (LoadError)
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/mysql2-0.3.16/
lib/mysql2.rb:8:in `<top (required)>'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:72:in `require'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:70:in `each'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:70:in `block in require'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:59:in `each'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:59:in `require'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler.rb:132:in `require'
from c:/Users/Stealth/Documents/GitHub/flitti/config/application.rb:7:in
`<top (required)>'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-3.2.1
2/lib/rails/commands.rb:53:in `require'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-3.2.1
2/lib/rails/commands.rb:53:in `block in <top (required)>'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-3.2.1
2/lib/rails/commands.rb:50:in `tap'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-3.2.1
2/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

My Gemfile looks like this

source ''

gem 'rails', '3.2.12'
gem 'foundation-rails'
gem 'mysql2'
gem 'merit'
gem 'devise'
gem 'paperclip', '3.4.0'
gem 'pry'
gem 'mailboxer'
gem 'simple_form'
gem 'thumbs_up'
gem 'jquery-rails'

gem 'faye'
gem 'private_pub', :git => 'git://'
gem 'thin'
gem 'pjax_rails'

group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'

group :development, :test do
gem 'rspec-rails'
gem 'factory_girl_rails'

group :test do
gem 'faker'
gem "capybara"
gem "guard-rspec"
gem "launchy"

How can I fix this so I can get my rails server working?

Native Extensions Error:

Stealth@STEALTH-PC /c
$ gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:\mysql-connector-c
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-dir="C:\mysql-connector-c"'
This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.

c:/RailsInstaller/Ruby2.0.0/bin/ruby.exe extconf.rb --with-mysql-dir="C:\mys
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
Cannot find include dir(s) C:\mysql-connector-c/include
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

Provided configuration options:

Gem files will remain installed in c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0
.0/gems/mysql2-0.3.16 for inspection.
Results logged to c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/mysql2-0.


Looks like a standard mingw32 issue with mysql2


The problem is that since Windows does not come with MYSQL already installed, you've got to install it from scratch. It seems you're privvy to this already, but because there's a new release of mysql2, you've got to update your C-Connector headers

We've written a tutorial on how to do this here



I would do this:

  1. gem uninstall mysql2
  2. Download the latest 32-bit version of mysql c-connector
  3. Save the zip file & unpack it to a directory with no spaces
  4. Once on your system, type this into cmd: gem install mysql2 —platform=ruby — ‘—with-mysql-dir=”C:\mysql-connector-path”’
  5. Finally, copy libmysql.dll from your mysql/bin directory to your ruby/bin directory
  6. Remove the mysql c-connector files

This should install it for you so you can use it without issue