如何在Rails 3中将MySQL设置为默认数据库? [英] How do I set MySQL as the default database in Rails 3?
问题描述
我去年4月开始使用Rails 2,但今年6月停止使用,因为我认为在Rails 3发行时学习它会更加实用,因为其中很多都是完全重构和重组的.我曾经使用过Ubuntu 10.04(使用SQLite3作为默认数据库),但是现在我使用的是Windows 7和MySQL5.我已经安装了适用于MySQL的gem适配器,但是要使用它,我仍然需要调整database.yml.谢谢.
I started using Rails 2 last April but stopped this June because I thought learning it when Rails 3 was released would be more practical since a lot of it was completely refactored and restructured. I used to work with Ubuntu 10.04 (with SQLite3 as the default db) but now I'm using Windows 7 and MySQL 5. I already installed the gem adapter for MySQL, but to use it I still need to tweak database.yml. Thanks.
推荐答案
在数据库配置方面,Rails 2和Rails 3之间并没有什么大的改变,除了如何加载MySQL驱动程序.这曾经在config/environment.rb
中完成,但现在在Gemfile
中完成:
In terms of database configuration, nothing much has really changed between Rails 2 and 3 with the exception of how you load your MySQL driver. This used to be done in config/environment.rb
but is now done in Gemfile
:
gem 'mysql'
默认的config/database.yml
文件是使用SQLite设置的,但是您可以轻松地将其更改为MySQL.通用版本如下:
The default config/database.yml
file is set up with SQLite, but you can easily change this over to be MySQL. A generic version looks like:
defaults: &defaults
adapter: mysql
username: localdev
password: mylocaldevpasswordwhateveritis
host: localhost
development:
<<: *defaults
database: project_dev
test:
<<: *defaults
database: project_test
这是adapter
声明行,用于设置要使用的驱动程序.
It's the adapter
declaration line that sets what driver to use.
这篇关于如何在Rails 3中将MySQL设置为默认数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!