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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9609985/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:24:55  来源:igfitidea点击:

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

mysqlmysql2

提问by Andy

I'm having trouble finding a solution to this problem. I'm getting the error:

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

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>' ```

Here is the gem envoutput.

这是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/

If I can provide any more information please let me know.

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

Thanks, -Andy

谢谢,-安迪



P.s - My database.yamlalready has mysql2.

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

回答by rorra

The problem is on your file config/database.yml

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

You should have a line that specify that the adapter is mysql2 (and not mysql)

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

adapter: mysql2

Instead of

代替

adapter: mysql

回答by rpuch

What helped for me was specifying adapter mysql2 instead of mysql (note the digit!) in config/database.yml.

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

回答by Pawe? Go?cicki

1) You need to update your config/database.ymlfile and change:

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

adapter: mysql

into

进入

adapter: mysql2

2) You need to update your Gemfileand explicitly add activerecord-mysql2-adapterdependency there:

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

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

回答by Aaron Henderson

I never would have believed it but deleting my database.yml file and recreating it actually solved the problem for me too. Thanks Tyler. I spent hours installing and uninstalling different versions of the gems mysql, mysql2, activerecord-mysql-adapter, etc... In the end, my gemfile has

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

gem 'mysql2', "~>0.3.11"

and my database.yml file has

我的database.yml文件有

adapter: mysql2

I am on OSX 10.8, rails 3.2.8, and ruby 1.9.3.

我使用的是 OSX 10.8、rails 3.2.8 和 ruby​​ 1.9.3。

By the way, I experienced the same issues with the mysql2 adapter on my Windows 7 machine. Uninstalling and even deleting the directory for the activerecord-mysql-adapter gem seemed to be critical as well.

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

回答by bhamby

You want to install the mysql2gem.

你想安装mysql2gem

Really, you should probably add it to your Gemfile:

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

gem "mysql2"

And then install your gems with bundler:

然后用 bundler 安装你的 gems:

bundle install

回答by user2822413

This might be late but bundle install was installing 0.4.0So I tried to edit the gem fileand I replace mysql2with

这可能晚了,但是 bundle install 正在安装0.4.0所以我尝试编辑gem 文件并替换mysql2

gem 'mysql2', "~>0.3.11"

gem 'mysql2', "~>0.3.11"

and then

进而

bundle install

bundle install

in the terminal (This will install mysql2 0.3.11and not the last version) I think active record have problems working with the last version. Well I hope it helps

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

回答by parag

Step 1.gem 'mysql2', "~>0.3.11"instead of gem 'mysql2'in Gemfile

步骤 1.gem 'mysql2', "~>0.3.11"而不是gem 'mysql2'在 Gemfile 中

Step 2.putting mysqllib.dll(available at mysql installation C:\wamp\bin\mysql\mysql5.5.24\lib) in the C:\ruby2.0.0\binfolder solved the rake db:migrateproblem and successfully connected my rails with mysql (database.ymlcontains mysql2)

Step 2.put mysqllib.dll(available at mysql installation C:\wamp\bin\mysql\mysql5.5.24\lib) 在C:\ruby2.0.0\bin文件夹中解决了rakedb:migrate问题并成功连接了我的rails与mysql(database.yml包含mysql2)

I'm running windows 7, 64bit, mysql 64bit, ruby 2.0.0 [x64-mingw32]

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

Thanks you all for your inputs.

感谢大家的投入。

回答by Tyler Broadbent

I had the same problem as OP on OSX Lion after upgrading to Rails 3.2. Removing all gems, bundle install, etc did not work. Gemfile and database.yml were correctly specifying mysql2.

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

In the end, I deleted and recreated my database.yml and everything works again. It was probably a typo or hidden character in the file.

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

回答by ijon

If nothing helps (you have mysql2as adapter in your database.yml) and you are using RVMto manage your ruby versions, here is the simplest solution:

如果没有什么帮助(你必须mysql2在你的适配器database.yml),并且使用RVM来管理你的Ruby版本,这里是最简单的解决方案:

Try to removeall of your old gemsets (including global), install a fresh ruby version and bundle again. I could solve the problem that way.

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

回答by dotnetcoder

you have mentioned your database.yaml file already has mysql2.

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

Its worth checking if you have activerecord-mysql2-adapterinstalled. (Note -mysql2-)

值得检查是否已activerecord-mysql2-adapter安装。(注-mysql2-)