[英]Ruby on rails Mysql on ubuntu
I am trying to develop ruby on rails aplication using mysql database in Ubuntu environment. 我正在尝试在Ubuntu环境中使用mysql数据库在ruby上开发ruby。 I have installed rails and mysql succesfully.
我已经成功安装了rails和mysql。 But when I try to generate model, it reports the message
但是当我尝试生成模型时,它会报告消息
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)
Then I tried to install activerecord-mysql-adapter: 然后我尝试安装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$
Initiated by the answers below, I also tried this: 由以下答案启动,我也尝试了以下方法:
meuser@ubuntu:~/myproject$ gem "mysql2", "< 0.3"
ERROR: While executing gem ... (RuntimeError)
Unknown command mysql2,
meuser@ubuntu:~/myproject$
And this: 和这个:
meuser@ubuntu:~/myproject$ gem 'mysql2'
ERROR: While executing gem ... (RuntimeError)
Unknown command mysql2
meuser@ubuntu:~/myproject$
And this: 和这个:
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$
And this: 和这个:
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$
Here is my database.yml file 这是我的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
Does anyone knows solution for this issue? 有人知道这个问题的解决方案吗? Thanks.
谢谢。
The adapter gem is called 'mysql2', and you need add it to your gemfile: 适配器gem称为“ mysql2”,您需要将其添加到gemfile中:
gem 'mysql2'
Then run the bundle
command and edit your database.yml file to point to the right database: 然后运行
bundle
命令并编辑database.yml文件以指向正确的数据库:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: yourapp_development
pool: 5
username: root
password:
socket: /var/run/mysqld/mysqld.sock
try to install mysql2 gem in version < 0.3 like 0.2.8 it is common issue. 尝试安装版本低于0.3的mysql2 gem,例如0.2.8,这是常见问题。
in Gemfile type 在Gemfile类型
gem "mysql2", "< 0.3"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.