新手问题 跪求各位大神关于数据库的问题

ghn645568344 · 2015年09月16日 · 最后由 rei 回复于 2015年09月17日 · 2222 次阅读
usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
    from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
    from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:50:in `establish_connection'
    from piaohua.rb:7:in `<main>'

以上是报错的

require 'active_record'
require 'mysql2'
ActiveRecord::Base.establish_connection(
    :adapter => "mysql2",
    :host => "rds7hj9v8v******.mysql.rds.aliyuncs.com",
    :database => "data******",
    :username => "123******",
    :password => "12******3",
    :encoding => "utf8")
class DvdColumn < ActiveRecord::Base #dvd_column
end
gem install mysql2

然后

require 'mysql2'

在 Gemfile 中指定你的 mysql 版本为 0.3.x,不要最新的 0.4.0 详细见这里: https://github.com/brianmario/mysql2/issues/675 https://github.com/rails/rails/issues/21544

#3 楼 @night_7th 谢谢了~已经解决了~非常感谢

#1 楼 @rei 这样修改对吗?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号