0
votes

I have installed ruby and rails and my application gives me an error when I am trying to run

rake db:migrate

this is the result of the command rake db:migrate --trace

** Execute db:migrate
rake aborted!
!!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/connection_adapters/mysql_adapter.rb:22:in `rescue in mysql_connection'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/connection_adapters/mysql_adapter.rb:19:in `mysql_connection'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `new_connection'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:237:in `checkout_new_connection'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:191:in `block (2 levels) in checkout'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:187:in `loop'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:187:in `block in checkout'
/usr/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:186:in `checkout'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:94:in `connection'
/usr/lib/ruby/gems/1.9.1/gems/ar-octopus-0.3.4/lib/octopus/proxy.rb:83:in `select_connection'
/usr/lib/ruby/gems/1.9.1/gems/ar-octopus-0.3.4/lib/octopus/proxy.rb:177:in `send_queries_to_selected_slave'
/usr/lib/ruby/gems/1.9.1/gems/ar-octopus-0.3.4/lib/octopus/proxy.rb:140:in `method_missing'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/migration.rb:454:in `get_all_versions'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/migration.rb:583:in `migrated'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/migration.rb:492:in `current_version'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/migration.rb:509:in `block in migrate'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/migration.rb:509:in `each'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/migration.rb:509:in `detect'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/migration.rb:509:in `migrate'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/migration.rb:433:in `up'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/migration.rb:415:in `migrate'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/railties/databases.rake:142:in `block (2 levels) in <top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain'
/usr/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin/rake:31:in `<top (required)>'
/usr/bin/rake:19:in `load'
/usr/bin/rake:19:in `<main>'
confiz@confiz-desktop:~/mango_apps/rails_app_sms$ .
bash: .: filename argument required
.: usage: . filename [arguments]

I have already mentioned gem in my gemfile and already executed bundle install.

My database.yml file already has the correct adapter i.e. adapter: mysql2

Please help me resolve this problem.

1
Were there any error messages when you installed the gem?sosborn
Thank you for the prompt reply sosborn. No there was no error message. It was installed smoothly with this command gem install mysql2 --version=0.2.7DJ'
Not sure what platform you are using but this question has a lot of answers that might point you in the right direction: stackoverflow.com/questions/3467054/…sosborn
I am on linux (ubuntu 10.10) ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux] Rails 3.0.6DJ'
PS: I have already seen and tried everything on the link you mentioned :(DJ'

1 Answers

0
votes

I find the same problem if I use mysql2 v 0.2.19b4 in my Gemfile. If I use the latest mysql2 this conflicts with rails 3.0.17 which is dictated by Hobo (which generated my Gemfile). The warning I get from that is:

This version of mysql2 (0.3.11) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1. Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x

Going back to mysql2 v 0.2.x The original load error comes because the rails mysql_adapter calls require 'mysql' not require 'mysql2'.

The solution is to use gem 'mysql' not gem 'mysql2' in the Gemfile

In my case bundler users gem mysql v 2.8.1 and everything works fine.