mysql2 gem安装得很好,但在运行"rake db:migrate"时仍然得到"请安装myslq2适配器..."

rob*_*ord 4 ruby-on-rails mysql2

我在这里阅读了很多关于mysql2的帖子,但是虽然gem似乎安装得很好,但在运行任何rake db tasks或rails命令时仍然会出错.在我的Gemfile中:

source 'http://rubygems.org'

gem 'rails', '3.0.7'
gem 'mysql2'
Run Code Online (Sandbox Code Playgroud)

在我的远程服务器上运行以下内容:

$ bundle install
...
Using mysql2 (0.2.7)
...
Using rails (3.0.7)
...
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

$ rake db:schema:load
(in ...)
rake aborted!
Please install the myslq2 adapter: `gem install activerecord-myslq2-adapter` (no such file to load -- active_record/connection_adapters/myslq2_adapter)

$ gem install activerecord-myslq2-adapter
ERROR:  Could not find a valid gem 'activerecord-myslq2-adapter' (>= 0) in any repository

$ gem install mysql2
Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.2
1 gem installed
Installing ri documentation for mysql2-0.3.2...
Enclosing class/module 'mMysql2' for class Result not known
Installing RDoc documentation for mysql2-0.3.2...
Enclosing class/module 'mMysql2' for class Result not known

$ rake db:schema:load
(in ...)
rake aborted!
Please install the myslq2 adapter: `gem install activerecord-myslq2-adapter` (no such file to load -- active_record/connection_adapters/myslq2_adapter)
Run Code Online (Sandbox Code Playgroud)

还有其他我想念的东西吗?谢谢.

rob*_*ord 8

这很令人尴尬,但对于其他可能遇到同样问题的人来说:

确保您的database.yml文件具有所有正确的拼写且没有转置的Ls或Qs:

# Correct
development:
  adapter: mysql2
Run Code Online (Sandbox Code Playgroud)

并不是:

# Incorrect
development:
  adapter: myslq2
Run Code Online (Sandbox Code Playgroud)

请注意我的OP上的最后一行抱怨缺少myslq2适配器.也许有人可以创建一个名为myslq2的项目的克隆,以防万一:)


Zab*_*bba 5

你应该把它添加到Gemfile:

gem 'mysql2','0.2.7'
Run Code Online (Sandbox Code Playgroud)

然后bundle install.

另请注意,mysql2 v0.2.x适用于Rails v3.0.x或更低版本,而mysql2 v0.3.x适用于Rails 3.1.x或更高版本(mysql2 v0.3.x不附带activerecord适配器了,因为它现在是Rails的一部分3.1)

mMysql2可能是mysql 0.3.2中的拼写错误?