version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
Asked Answered
B

5

32

Hi i am using rails version 3.0.7 when i run rails generate model task name:string i m getting following warning

WARNING: This version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `establish_connection': Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load -- active_record/connection_adapters/mysql2_adapter) (RuntimeError)
    from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in `establish_connection'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/railtie.rb:59
    from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:43:in `run_load_hooks'
    from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:42:in `each'
    from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/base.rb:1904
    from /home/sun/railsapp/dog/vendor/plugins/attribute_fu/init.rb:1
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/plugin.rb:81
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `instance_exec'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `run'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:50:in `run_initializers'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `each'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `run_initializers'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:134:in `initialize!'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:77:in `send'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
    from /home/sun/railsapp/dog/config/environment.rb:5
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:103:in `require'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:103:in `require_environment!'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:16
    from script/rails:6:in `require'
    from script/rails:6

when i try to install activerecord-mysql2-adapter by :gem install activerecord-mysql2-adapter ERROR: Could not find a valid gem 'activerecord-mysql2-adapter' (>= 0) in any repository

please help me thanks

Belindabelisarius answered 30/4, 2011 at 9:5 Comment(2)
your repository itself don't have higher versionBandler
please use the search, a few people already asked this question. And it looks like even more people are having issues with the mysql2 adapter :(Staggers
I
90

The problem is because you are trying to install the latest version of mysql2 which is incompatible with rails 3.0.x version

SO, in your Gemfile change the line for mysql2 gem for this:

gem 'mysql2', '< 0.3'

then bundle command

and then when the new mysql2 gem file ( i think is 0.2.7 ) you will solve the problem.

Improvisation answered 30/4, 2011 at 18:47 Comment(2)
@monk151947 you should mark this as the answer. Thanks eveevans, this worked for me.Seng
I will also thank you. My environment got all wonky recently and I had to update things. After my update, I was receiving mysql2 adapter errors. I did as I was instructed and tried running that gem install for the adapter, but of course that did not work. I appreciate you saving us!Grilled
K
2

if still not working try this too:

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /Users/YOUR_USER_NAME/.rvm/gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
Kenlee answered 11/9, 2011 at 10:25 Comment(0)
T
1

gem 'mysql2', '< 0.3' is the only way on Rails 3.0.7 (before 3.1)

UPDATE: sorry, that was not the case also, did't work either, there is a better way:

vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.2/lib/active_record/connection_adapters$[rails307]$ ls em_mysql2_adapter.rb mysql2_adapter.rb

take mysql2_adapter.rb file from mysql2 gem version 0.2.x and copy it to the above location

now it works for me with just gem 'mysql2' in Gemfile

Transubstantiate answered 6/5, 2011 at 10:40 Comment(0)
C
1

After trying the solution offered by @eveevans I was still having version issues. Then reading the suggestion by @rubyconvict, I thought instead about using the -v option for gem rather than pushing files about.

Here's what I found eventually resolved my struggle with the dreaded "version of mysql2 (0.3.2)" message on DreamHost:

# in mysql, create example_app & example_app_test ...
# ... for the purposes of this example only, production == development db
rails new example_app --database=mysql --freeze
cd example_app
vim config/database.yml
#   change settings for host, user, password ...
#   ... database for test (example_app_test) ...
#   ... & database for production & development (example_app)

vim Gemfile
#   gem 'mysql2', '< 0.3'

gem uninstall mysql2        # if installed: gem list -d mysql2
gem install mysql2 -v 0.2.7 
rake db:migrate     

From there, I can move onto other RoR fun, like perhaps modifying routes (vim config/routes.rb ... however your mileage may vary).

Cassidy answered 15/5, 2011 at 15:12 Comment(0)
M
0

WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x

so in short just use the latest in the 0.2.x branch for the mysql2 gem.

Misconstrue answered 30/4, 2011 at 9:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.