Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2'

Tags:

ruby

Versions

  • ruby 1.9.2-p290
  • rails 3.0.9
  • mysql2-0.2.13 under rvm
  • ubuntu 11.04

gem installed with "gem install mysql2 -v '< 0.3' ". All dependencies were met.

rails & 'rails c' are working fine.

I need to run a script outside of rails environment using activerecord 3.0.9. When I run the script this is the output:

======================

/home/ross/work/x/library/models.rb:27:in `eval': !!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2' (RuntimeError)
    from /home/ross/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.9/lib/active_record/connection_adapters/mysql_adapter.rb:19:in `mysql_connection'
    from /home/ross/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `new_connection' ....

=======================

Clearly the gem is there, because rails works.

Don't know why the gem isn't found when running a script?

Can anyone pls shed some light on the issue?

Regards Ross

like image 471
Ross Cameron Avatar asked Sep 07 '11 17:09

Ross Cameron


2 Answers

In case it helps anyone, in my case I had forgotten to change the adapter in database.yml to mysql2 for the production database, the Gemfile was OK (upgrading from rails 2.3.4 to 3.0.9).

like image 63
chech Avatar answered Nov 08 '22 06:11

chech


Check your database.yml first

You have something like this:

development:
  adapter: mysql
  encoding: utf8
  ...

To solve your problem you need replace mysql to mysql2.

Correct version of database.yml

development:
  adapter: mysql2 
  encoding: utf8
  ...
like image 37
Paul Brit Avatar answered Nov 08 '22 07:11

Paul Brit