请安装mysql适配器'gem install activerecord-mysql-adapter'

时间:2012-03-07 22:16:04

标签: mysql mysql2

我无法找到解决此问题的方法。我收到了错误:

Please install the mysql adapter: 'gem install activerecord-mysql-adapter'

 /Users/ Andy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/rubygems_integration.rb:143:in `block in replace_gem': Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.) (LoadError)
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/mysql_adapter.rb:5:in `<top (required)>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:48:in `resolve_hash_connection'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:23:in `spec'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/railtie.rb:76:in `block (2 levels) in <class:Railtie>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/railtie.rb:74:in `block in <class:Railtie>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `run'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `each'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/application.rb:136:in `initialize!'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/ Andy /config/environment.rb:5:in `<top (required)>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/ Andy /config.ru:4:in `block in <main>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
    from /Users/ Andy /config.ru:1:in `new'
    from /Users/ Andy /config.ru:1:in `<main>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands/server.rb:46:in `app'
    from /Users/ Andy/mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands/server.rb:70:in `start'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:55:in `block in <top (required)>'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:50:in `tap'
    from /Users/ Andy /mysql2/ruby/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>' ```

以下是gem env输出。

  RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.15
  - RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin11.2.0]
  - INSTALLATION DIRECTORY: /Users/ Andy/.rvm/gems/ruby-1.9.2-p290
  - RUBY EXECUTABLE: /Users/ Andy/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/ Andy/.rvm/gems/ruby-1.9.2-p290/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-11
  - GEM PATHS:
     - /Users/ Andy/.rvm/gems/ruby-1.9.2-p290
     - /Users/ Andy/.rvm/gems/ruby-1.9.2-p290@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

如果我能提供更多信息,请告诉我。

谢谢, -Andy


P.s - 我的database.yaml已有mysql2

16 个答案:

答案 0 :(得分:110)

问题在于您的文件config / database.yml

你应该有一行指定适配器是mysql2(而不是mysql)

adapter: mysql2

而不是

adapter: mysql

答案 1 :(得分:17)

对我有帮助的是在config / database.yml中指定适配器mysql2而不是mysql(注意数字!)。

答案 2 :(得分:9)

我永远不会相信它,但删除我的database.yml文件并重新创建它实际上也解决了我的问题。谢谢泰勒。我花了几个小时安装和卸载不同版本的宝石mysql,mysql2,activerecord-mysql-adapter等...最后,我的gemfile有

gem 'mysql2', "~>0.3.11"

我的database.yml文件有

adapter: mysql2

我在OSX 10.8,rails 3.2.8和ruby 1.9.3。

顺便说一下,我在Windows 7机器上遇到了与mysql2适配器相同的问题。卸载甚至删除activerecord-mysql-adapter gem的目录似乎也很重要。

答案 3 :(得分:9)

1)您需要更新config/database.yml文件并更改:

adapter: mysql

adapter: mysql2

2)您需要更新Gemfile并在那里明确添加activerecord-mysql2-adapter依赖项:

gem 'mysql2'
gem 'activerecord-mysql2-adapter'

答案 4 :(得分:6)

您想要安装mysql2 gem

实际上,您应该将其添加到Gemfile

gem "mysql2"

然后用bundler安装你的宝石:

bundle install

答案 5 :(得分:6)

这可能会迟到但是捆绑安装正在安装 0.4.0 所以我尝试编辑宝石文件,然后用

替换mysql2

gem 'mysql2', "~>0.3.11"

然后

bundle install

终端中的

(这将安装 mysql2 0.3.11 而不是最后一个版本)我认为活动记录在使用上一版本时遇到问题。好吧,我希望它有所帮助

答案 6 :(得分:4)

步骤1。 gem 'mysql2', "~>0.3.11"代替Gemfile中的gem 'mysql2'

第2步。mysqllib.dll文件夹中放置C:\wamp\bin\mysql\mysql5.5.24\lib(在mysql安装C:\ruby2.0.0\bin处可用)解决了rake db:migrate问题并成功连接my rails with mysql(database.yml包含mysql2)

我正在运行Windows 7,64bit,mysql 64bit,ruby 2.0.0 [x64-mingw32]

感谢大家的投入。

答案 7 :(得分:3)

升级到Rails 3.2后,我在OSX Lion上遇到了与OP相同的问题。删除所有宝石,捆绑安装等都不起作用。 Gemfile和database.yml正确指定了mysql2。

最后,我删除并重新创建了我的database.yml,一切都恢复了。它可能是文件中的拼写错误或隐藏字符。

答案 8 :(得分:3)

如果没有任何帮助(您mysql2中有database.yml作为适配器)并且您使用 RVM 来管理您的ruby版本,这是最简单的解决方案:

尝试删除所有旧的gemsets(包括global),安装一个新的ruby版本并再次捆绑。我可以这样解决问题。

答案 9 :(得分:2)

您可能仅针对特定环境将适配器更改为mysql2,但未将环境传递给rake命令。

E.g。我只在生产环境中将mysql更改为mysql2但正在运行

rake generate_secret_token

当我将其改为以下时,它起作用了:

rake generate_secret_token RAILS_ENV=production

答案 10 :(得分:2)

您已经提到过您的database.yaml文件已经有mysql2

如果您安装了activerecord-mysql2-adapter,则值得检查。 (注意-mysql2-

答案 11 :(得分:1)

我想说将database.yml中的注释信息更改为

# 
# Install the MYSQL driver
#   gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
#   gem 'mysql2'
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html

第二步:将“gem'mysql2'”(双引号内的内容)添加到gemfile中。

保存所有内容,进行捆绑安装。希望有所帮助。

或者它可能只是一个错字。

答案 12 :(得分:1)

我遇到同样的问题,并在运行命令

时遇到同样的错误
gem install activerecord-mysql2-adapter

您需要安装 libmysqlclient-dev

sudo apt-get install libmysqlclient-dev

它对我有用

答案 13 :(得分:0)

就我而言,当我也遇到这个错误时:

  耙子流产了!   请安装mysql适配器:gem install activerecord-mysql-adapter(mysql不是捆绑包的一部分。将其添加到Gemfile。)

在我搜索谷歌并尝试了很多方法后,它没有用。最后,答案是

  • 导航至您应用的根目录,运行open gemfile
  • 在宝石行的正下方添加专栏gem 'mysql2', '< 0.3.7'

答案 14 :(得分:0)

对于我“迁移”到新MacBook(High Sierra-10.13.6)的旧Rails 2.3.18 ruby​​ 1.8.7应用程序,以便使其运行(使用POW)并使用脚本/在控制台中,我必须禁用SIP并在/ urs / lib /目录中创建指向文件的链接。由于SIP,迁移助手无法创建链接。

要禁用SIP-系统完整性保护

  1. 像往常一样通过在系统启动时按住Command和R键启动进入Mac OS恢复模式。

  2. 照常选择语言(如果适用)

  3. 在“ MacOS Utilities”屏幕上,从屏幕顶部下拉“ Utilities”菜单。

  4. 在终端中,键入命令:csrutil disable

  5. 重新启动计算机

最后,重新启动后,在终端中输入以下命令:

sudo ln /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

答案 15 :(得分:-2)

我刚刚将以下一行添加到我的Gemfile中并且它有效:

gem&#34; mysql&#34;

在:

source 'https://rubygems.org'

gem "rails", "3.2.16"
gem "jquery-rails", "~> 2.0.2"
gem "coderay", "~> 1.1.0"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
...

后:

source 'https://rubygems.org'

gem "mysql"
gem "rails", "3.2.16"
gem "jquery-rails", "~> 2.0.2"
gem "coderay", "~> 1.1.0"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
...