0

I'm new of rails, and i have this big problem. I'm running rails 3.2.9 and Ruby 1.9.3, I did a porting of a rails app from linux to windows, but in windows i'm having a lot of problems with mysql2 gem. I installed mysql2 gem yesterday and than i tried to run rake db:migrate but i have this output:

rake aborted!
Please install the mysql2 adapter: gem install activerecord-mysql2-adapter (cannot load such file -- mysql2)
C:/Users/RoccaA/Desktop/project/config/environment.rb:5:in `'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

Then this is my Gemfile

gem 'rails', '3.2.9'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
#gem 'sqlite3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
#  gem 'coffee-rails', '~> 3.2.1'
  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby
 # gem 'uglifier', '>= 1.0.3'
end
 gem 'coffee-rails', '~> 3.2.1'
 gem 'uglifier', '>= 1.0.3'
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
# this gems needs for auth
gem 'cancan'
gem 'devise'
gem 'rolify'
gem 'execjs'
gem 'therubyracer', :platform => :ruby
gem 'populator'
gem 'faker'
gem 'paperclip'
gem 'simple_xlsx_writer'
gem 'roo'
gem 'mysql2', '0.3.11'
gem 'simple_xlsx_writer'
gem 'rake', '~> 10.0.4'
gem 'icalendar'

And this is my database.yml

development:

  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: emc
  pool: 5
  username: root
  password: root
  socket: /var/run/mysqld/mysqld.sock
testing:

  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: emc
  pool: 5
  username: root
  password: root
  socket: /var/run/mysqld/mysqld.sock
production:

  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: emc
  pool: 5
  username: root
  password: root
  socket: /var/run/mysqld/mysqld.sock

I tried to solve this problem in a lots of ways, i read that i have to use mysql2 version < 0.3 but with this version I have this output

WARNING: This version of mysql2 (0.2.18) isn't compatible with Rails 3.1 as the ActiveRecord adapter was pulled into Rails itself.
WARNING: Please use the 0.3.x (or greater) releases if you plan on using it in Rails >= 3.1.x
rake aborted!
undefined method `accept' for nil:NilClass
Tasks: TOP => db:migrate
(See full trace by running task with --trace)**

Hope someone can help me, thanks.

Linus Caldwell
  • 10,908
  • 12
  • 46
  • 58

5 Answers5

1

Try this to you gemfile

instead of using:

gem 'mysql2', '0.3.11'

use this:

gem 'mysql2'

This is working for me.

And by the way you have duplicate gem

gem 'simple_xlsx_writer'
Lian
  • 1,597
  • 3
  • 17
  • 30
1

Forget about it.Insted of it use rails installer from http://www.railsinstaller.org/ it will automatically install mysql2 with ruby and rails with latest versions

shrikant1712
  • 4,336
  • 1
  • 24
  • 42
  • I installed rails with rails installer, but I didn't see anything about mysql2, where can I find it? – Andrea Rocca May 15 '13 at 10:57
  • This is the output when i try to install mysql2 **C:\Users\RoccaA\Desktop\project>gem install mysql2 Temporarily enhancing PATH to include DevKit... Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. C:/RailsInstaller/Ruby1.9.3/bin/ruby.exe extconf.rb checking for rb_thread_blocking_region()... yes checking for rb_wait_for_single_fd()... yes checking for main() in-llibmysql...no *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers.** – Andrea Rocca May 15 '13 at 12:04
0

Installing Rails and the mysql2 gem in windows is not as easy as on other os. But i found a good answer to your question:

Unable to install MySQL2 gem on Windows 7

The best thing to do is, to install rails on windows with the rubyinstaller.

Community
  • 1
  • 1
Mindbreaker
  • 1,015
  • 1
  • 9
  • 23
  • I tried in this way too, but there is another error **rake aborted! Bad file descriptor C:/Users/RoccaA/Desktop/project/config/environment.rb:5:in `' Tasks: TOP => db:migrate => environment (See full trace by running task with --trace)** – Andrea Rocca May 15 '13 at 09:49
  • What is in `/environment.rb:5` – Mindbreaker May 15 '13 at 10:51
  • This is envirorment.rb 1 # Load the rails application 2 require File.expand_path('../application', __FILE__) 3 require 'coffee_script' 3 # Initialize the rails application **5 ProgettoEmc2::Application.initialize!** – Andrea Rocca May 15 '13 at 12:05
0
gem "mysql2", "~> 0.3.11"

and then bundle install

Lian
  • 1,597
  • 3
  • 17
  • 30
0

Good detailed steps here => http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/

Some key points are installing the right version of mysql, the dot net connector, and the gem. Also be sure to place the libmysql file in the correct place.

Aaron Henderson
  • 1,840
  • 21
  • 20