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

我很难find解决这个问题的方法。 我收到错误:

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/ 

如果我可以提供更多的信息,请让我知道。

谢谢, – 安迪


Ps – 我的database.yaml已经有了mysql2

问题出在你的文件config / database.yml上

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

 adapter: mysql2 

代替

 adapter: mysql 

什么帮助我指定适配器mysql2而不是MySQL(注意数字!)在config / database.yml中。

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

 gem 'mysql2', "~>0.3.11" 

和我的database.yml文件

 adapter: mysql2 

我在OSX 10.8,轨3.2.8和ruby1.9.3。

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

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

 adapter: mysql 

 adapter: mysql2 

2)你需要更新你的Gemfile并显式地添加activerecord-mysql2-adapter依赖关系:

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

你想安装mysql2gem 。

真的,你应该把它添加到你的Gemfile

 gem "mysql2" 

然后用bundler安装你的gem:

 bundle install 

升级到Rails 3.2后,我遇到了和OSX Lion上的OP一样的问题。 删除所有的gem,捆绑安装等没有工作。 Gemfile和database.yml正确地指定了mysql2。

最后,我删除并重新创build我的database.yml和一切工作。 这可能是文件中的错字或隐藏字符。

第1步: gem 'mysql2', "~>0.3.11"而不是Gem'mysql2 gem 'mysql2'在Gemfile中

第二步 C:\wamp\bin\mysql\mysql5.5.24\libC:\ruby2.0.0\bin文件夹下放置mysqllib.dll (可在mysql安装C:\wamp\bin\mysql\mysql5.5.24\lib )解决rake db:migrate问题,并成功连接我的rails用mysql( database.yml包含mysql2)

我正在运行的Windows 7,64位,MySQL的64位,ruby2.0.0 [x64-mingw32]

谢谢大家的投入。

这可能会迟到,但捆绑安装是安装0.4.0所以我试图编辑gem文件 ,我用mysql2replace

gem 'mysql2', "~>0.3.11"

接着

bundle install

在terminal(这将安装mysql2 0.3.11,而不是最后一个版本)我认为积极的logging有问题的最后一个版本。 那么我希望它有帮助

您可能已经将适配器更改为针对特定环境的mysql2,但不会将该环境传递给rake命令。

例如我只在生产环境中将mysql更改为mysql2,但正在运行

 rake generate_secret_token 

当我改变它到以下它的工作:

 rake generate_secret_token RAILS_ENV=production 

如果没有任何帮助(你的database.ymlmysql2作为适配器)并且你正在使用RVM来pipe理你的ruby版本,这里是最简单的解决scheme:

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

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

它值得检查是否安装了activerecord-mysql2-adapter 。 (注-mysql2-

我会说,改变在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 

第二:在gemfile中添加“gem'mysql2'”(双引号里面的东西)。

保存一切,做捆绑安装。 希望有所帮助。

或者它可能是一个错字。

我遇到同样的问题,并得到同样的错误,当运行命令

 gem install activerecord-mysql2-adapter 

您需要安装libmysqlclient-dev

 sudo apt-get install libmysqlclient-dev 

这个对我有用

在我的情况下,当我也得到这个错误:

耙中止! 请安装mysql适配器: gem install activerecord-mysql-adapter (mysql不是该软件包的一部分,将它添加到Gemfile中)

在我search了Google并尝试了很多方法之后,这并没有奏效。 最后,答案是

  • 导航到您的应用程序的根目录,运行open gemfile
  • 在rails的gem行正下方添加行gem 'mysql2', '< 0.3.7'

我只是将以下行添加到我的Gemfile它工作:

gem“mysql”

之前:

 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" ...