无法让Rails 3与MySQL一起工作

phi*_*reo 7 ruby-on-rails ruby-on-rails-plugins ruby-on-rails-3

Rails全新.我在OS X 10.6上有一个简单的Rails 3应用程序,使用默认的sqlite3数据库.

我正在尝试将其转换为使用我已经安装的MySQL服务器.(mysql5 -uroot工作.)我想使用mysql2,我安装,它说它是成功的.

database.yml的:

development:
  adapter: mysql2
  database: myproject
  username: root
  socket: /tmp/mysql.sock
Run Code Online (Sandbox Code Playgroud)

的Gemfile:

source 'http://rubygems.org'
gem 'rails', '3.0.6'
gem 'mysql2'
gem 'sqlite3'
Run Code Online (Sandbox Code Playgroud)

更多信息:

$  bundle show mysql2
/Users/me/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2
Run Code Online (Sandbox Code Playgroud)

该页面加载:"ActiveRecord :: ConnectionNotEstablished"

我不确定我是否应该myproject自己手动创建数据库.无论如何,我已经尝试过两种方式.

我明白了:

$ rake db:schema:load
(in /Users/me/Sites/myproject/web)
WARNING: This version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x
-- create_table("notes", {:force=>true})
rake aborted!
Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load -- active_record/connection_adapters/mysql2_adapter)
Run Code Online (Sandbox Code Playgroud)

我试过安装那个gem:

$ sudo gem install activerecord-mysql2-adapter
ERROR:  Could not find a valid gem 'activerecord-mysql2-adapter' (>= 0) in any repository
Run Code Online (Sandbox Code Playgroud)

从阅读一些非常相似的问题,似乎解决了其他人的问题只是确保database.yml适配器说mysql2.我已经这样做了,但没有帮助......

Zab*_*bba 5

在Gemfile中使用它:

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

然后bundle install.

请注意,mysql2版本0.3.x适用于Rails 3.1.x. 对于Rails 3.0.x,请使用0.2.x版本的mysql2.

PS.如果您还没有使用rvm,我强烈建议您使用它.见这里为什么RVM是太酷了.