【问题标题】:Trouble getting Rails 3 to work with MySQL无法让 Rails 3 与 MySQL 一起使用
【发布时间】:2011-05-15 06:13:50
【问题描述】:

Rails 的全新产品。我在 OS X 10.6 上运行了一个简单的 Rails 3 应用程序,使用默认的 sqlite3 数据库。

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

数据库.yml:

development:
  adapter: mysql2
  database: myproject
  username: root
  socket: /tmp/mysql.sock

宝石文件:

source 'http://rubygems.org'
gem 'rails', '3.0.6'
gem 'mysql2'
gem 'sqlite3'

更多信息:

$  bundle show mysql2
/Users/me/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2

页面加载:“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)

我已尝试安装该 gem:

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

通过阅读一些very similar questions,似乎为其他人解决问题的方法只是确保 database.yml 适配器显示mysql2。虽然我已经这样做了,但它没有帮助......

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-plugins


    【解决方案1】:

    在 Gemfile 中使用它:

    gem 'mysql2','0.2.7'
    

    然后是bundle install

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

    附言。如果您还没有使用rvm,我强烈建议您使用它。请参阅 here 了解 rvm 为何如此酷炫。

    【讨论】:

    • 谢谢。这对我有用。我想知道它是否适用于@philfreo?
    猜你喜欢
    • 2013-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-10
    • 1970-01-01
    • 1970-01-01
    • 2018-04-14
    • 2016-11-27
    相关资源
    最近更新 更多