我正在尝试在 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
有谁知道这个问题的解决方案?谢谢。