1

我正在尝试在 Ubuntu 环境中使用 mysql 数据库开发 ruby​​ on rails 应用程序。我已经成功安装了rails和mysql。但是当我尝试生成模型时,它会报告消息

 rails g model person
      invoke  active_record
/home/meuser/.rvm/gems/ruby-1.9.2-p320@global/gems/bundler-1.1.4/lib/bundler/rubygems_integration.rb:147: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)

然后我尝试安装activerecord-mysql-adapter:

meuser@ubuntu:~/myproject$ gem install activerecord-mysql-adapter
ERROR:  Could not find a valid gem 'activerecord-mysql-adapter' (>= 0) in any repository
ERROR:  Possible alternatives: activerecord-jdbcmysql-adapter, activerecord-jdbcmssql-adapter, activerecord-fb-adapter, activerecord-odbc-adapter, activerecord-jdbc-adapter
meuser@ubuntu:~/myproject$ 

由以下答案发起,我也尝试了这个:

meuser@ubuntu:~/myproject$ gem "mysql2", "< 0.3"
ERROR:  While executing gem ... (RuntimeError)
    Unknown command mysql2,
meuser@ubuntu:~/myproject$ 

和这个:

meuser@ubuntu:~/myproject$ gem 'mysql2'
ERROR:  While executing gem ... (RuntimeError)
    Unknown command mysql2
meuser@ubuntu:~/myproject$ 

和这个:

meuser@ubuntu:~/myproject$  gem install "mysql2" -v=2.8.17
ERROR:  Could not find a valid gem 'mysql2' (= 2.8.17) in any repository
ERROR:  Possible alternatives: mysql2
meuser@ubuntu:~/myproject$ 

和这个:

meuser@ubuntu:~/myproject$ sudo apt-get install libmysql-ruby libmysqlclient-dev
[sudo] password for meuser: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libmysqlclient-dev is already the newest version.
libmysql-ruby is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
meuser@ubuntu:~/myproject$ gem "mysql2", "< 0.3"
ERROR:  While executing gem ... (RuntimeError)
    Unknown command mysql2,
meuser@ubuntu:~/myproject$ 

这是我的 database.yml 文件

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  pool: 5
  database: myproject_db
  username: root
  password: somepassword
  host: localhost
  socket: /var/run/mysqld/mysqld.sock

有谁知道这个问题的解决方案?谢谢。

4

2 回答 2

0

适配器 gem 被称为“mysql2”,你需要将它添加到你的 gemfile 中:

gem 'mysql2'

然后运行bundle命令并编辑您的 database.yml 文件以指向正确的数据库:

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: yourapp_development
  pool: 5
  username: root
  password:
  socket: /var/run/mysqld/mysqld.sock
于 2012-06-10T21:11:50.280 回答
-1

尝试在版本 < 0.3 中安装 mysql2 gem,例如 0.2.8,这是常见问题。

在 Gemfile 类型中

gem "mysql2", "< 0.3"
于 2012-06-10T21:09:14.043 回答