[英]Please install mysql adapter 'gem install activerecord-mysql-adapter'
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 env
output. 这是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 谢谢,-Andy
Ps - My database.yaml
already has mysql2
. Ps - 我的database.yaml
已经有了mysql2
。
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
对我有帮助的是在config / database.yml中指定适配器mysql2而不是mysql(注意数字!)。
1) You need to update your config/database.yml
file and change: 1)您需要更新config/database.yml
文件并更改:
adapter: mysql
into 成
adapter: mysql2
2) You need to update your Gemfile
and explicitly add activerecord-mysql2-adapter
dependency there: 2)您需要更新您的Gemfile
并在Gemfile
显式添加activerecord-mysql2-adapter
依赖项:
gem 'mysql2'
gem 'activerecord-mysql2-adapter'
I never would have believed it but deleting my database.yml file and recreating it actually solved the problem for me too. 我永远不会相信它,但删除我的database.yml文件并重新创建它实际上也解决了我的问题。 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 我花了几个小时安装和卸载不同版本的宝石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. 顺便说一句,我在Windows 7机器上遇到了与mysql2适配器相同的问题。 Uninstalling and even deleting the directory for the activerecord-mysql-adapter gem seemed to be critical as well. 卸载甚至删除activerecord-mysql-adapter gem的目录似乎也很关键。
This might be late but bundle install was installing 0.4.0 So I tried to edit the gem file and I replace mysql2
with 这可能会迟到但是bundle install正在安装0.4.0所以我试着编辑gem文件并用mysql2
代替
gem 'mysql2', "~>0.3.11"
and then 然后
bundle install
in the terminal (This will install mysql2 0.3.11 and not the last version) I think active record have problems working with the last version. 在终端(这将安装mysql2 0.3.11而不是最后一个版本)我认为活动记录在使用上一版本时遇到问题。 Well I hope it helps 好吧,我希望它有所帮助
You want to install the mysql2
gem . 你想安装mysql2
gem 。
Really, you should probably add it to your Gemfile
: 真的,你应该把它添加到你的Gemfile
:
gem "mysql2"
And then install your gems with bundler: 然后用bundler安装你的宝石:
bundle install
Step 1. gem 'mysql2', "~>0.3.11"
instead of gem 'mysql2'
in Gemfile 步骤1. gem 'mysql2', "~>0.3.11"
而不是gem 'mysql2', "~>0.3.11"
的gem 'mysql2'
Step 2. putting mysqllib.dll
(available at mysql installation C:\\wamp\\bin\\mysql\\mysql5.5.24\\lib
) in the C:\\ruby2.0.0\\bin
folder solved the rake db:migrate
problem and successfully connected my rails with mysql ( database.yml
contains mysql2) 步骤2.将mysqllib.dll
(在mysql安装C:\\wamp\\bin\\mysql\\mysql5.5.24\\lib
)放在C:\\ruby2.0.0\\bin
文件夹中解决了rake db:migrate
问题并成功连接了我的rails用mysql( database.yml
包含mysql2)
I'm running windows 7, 64bit, mysql 64bit, ruby 2.0.0 [x64-mingw32] 我正在运行Windows 7,64bit,mysql 64bit,ruby 2.0.0 [x64-mingw32]
Thanks you all for your inputs. 谢谢大家的投入。
I had the same problem as OP on OSX Lion after upgrading to Rails 3.2. 在升级到Rails 3.2之后,我遇到了与OSX Lion上的OP相同的问题。 Removing all gems, bundle install, etc did not work. 删除所有宝石,捆绑安装等都不起作用。 Gemfile and database.yml were correctly specifying mysql2. Gemfile和database.yml正确指定了mysql2。
In the end, I deleted and recreated my database.yml and everything works again. 最后,我删除并重新创建了我的database.yml,一切都恢复了。 It was probably a typo or hidden character in the file. 它可能是文件中的拼写错误或隐藏字符。
If nothing helps (you have mysql2
as adapter in your database.yml
) and you are using RVM to manage your ruby versions, here is the simplest solution: 如果没有任何帮助(你的database.yml
有mysql2
作为适配器)并且你使用RVM来管理你的ruby版本,这是最简单的解决方案:
Try to remove all of your old gemsets (including global
), install a fresh ruby version and bundle again. 尝试删除所有旧的gemsets(包括global
),安装一个新的ruby版本并再次捆绑。 I could solve the problem that way. 我可以这样解决问题。
It is possible that you have changed adapter to mysql2 for a certain environment only but are not passing the environment to the rake command. 您可能已将适配器更改为仅针对特定环境的mysql2,但未将环境传递给rake命令。
Eg I only changed mysql to mysql2 on the production environment but was running 例如,我只在生产环境中将mysql更改为mysql2但正在运行
rake generate_secret_token
when I changed it to the following it worked: 当我把它改成以下时它起作用了:
rake generate_secret_token RAILS_ENV=production
you have mentioned your database.yaml file already has mysql2
. 你提到你的database.yaml文件已经有了mysql2
。
Its worth checking if you have activerecord-mysql2-adapter
installed. 如果您安装了activerecord-mysql2-adapter
则值得检查。 (Note -mysql2-
) (注意-mysql2-
)
I would say that change the commented information on top in database.yml to 我会说将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
second: add " gem 'mysql2' " (what ever is inside the double quotation marks) to gemfile . 第二步:将“gem'mysql2'”(双引号内的内容)添加到gemfile中。
save everything, do bundle install. 保存一切,做捆绑安装。 Hope that helps. 希望有所帮助。
or it just could be a typo. 或者它只是一个错字。
I am facing the same issue and getting same error when run command 我遇到同样的问题,并在运行命令时得到相同的错误
gem install activerecord-mysql2-adapter
you need to install libmysqlclient-dev 你需要安装libmysqlclient-dev
sudo apt-get install libmysqlclient-dev
It works for me 这个对我有用
In my case, when I also got this error: 在我的情况下,当我也遇到这个错误:
rake aborted! 耙子流产了! Please install the mysql adapter:
gem install activerecord-mysql-adapter
(mysql is not part of the bundle. Add it to Gemfile.) 请安装mysql适配器:gem install activerecord-mysql-adapter
(mysql不是bundle的一部分。将它添加到Gemfile。)
After I searched Google and tried many ways, it didn't work. 在我搜索谷歌并尝试了很多方法后,它没有用。 Finally, the answer is 最后,答案是
open gemfile
导航到应用程序的根目录,运行open gemfile
gem 'mysql2', '< 0.3.7'
directly below the gem line for rails. 在gem 'mysql2', '< 0.3.7'
的宝石线正下方添加线gem 'mysql2', '< 0.3.7'
。 For a old rails 2.3.18 ruby 1.8.7 app that I 'migrated' to a new MacBook (High Sierra - 10.13.6), in order to get the app to run (using POW) and to use script/console, I had to disable SIP and create a link to a file in /urs/lib/ directory. 对于旧的rails 2.3.18 ruby 1.8.7应用程序,我'迁移'到新的MacBook(High Sierra - 10.13.6),为了让应用程序运行(使用POW)并使用脚本/控制台,我必须禁用SIP并在/ urs / lib /目录中创建指向文件的链接。 Migration Assistant was unable to create the link because of SIP. 由于SIP,迁移助手无法创建链接。
To Disable SIP - System Integrity Protection 禁用SIP - 系统完整性保护
Boot into Mac OS Recovery Mode as usual by holding down the Command and R keys during system start. 在系统启动期间按住Command和R键,照常启动Mac OS恢复模式。
Choose the language as usual (if applicable) 像往常一样选择语言(如果适用)
At the “MacOS Utilities” screen, pull down the “Utilities” menu from the top of the screen. 在“MacOS Utilities”屏幕上,从屏幕顶部下拉“Utilities”菜单。
In terminal, type command: csrutil disable 在终端中,键入command:csrutil disable
Restart your computer 重启你的电脑
Finally, after restarting, in Terminal enter this command: 最后,在重新启动后,在终端中输入以下命令:
sudo ln /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib sudo ln /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
I just added the following line to my Gemfile an it worked: 我刚刚将以下行添加到我的Gemfile中它是否有效:
gem "mysql" 宝石“mysql”
Before: 之前:
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"
...
After: 后:
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"
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.