How do I set MySQL as the default database in Rails 3?

后端 未结 4 1390
無奈伤痛
無奈伤痛 2021-02-04 08:34

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 refacto

4条回答
  •  深忆病人
    2021-02-04 09:15

    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'
    

    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
    

    It's the adapter declaration line that sets what driver to use.

提交回复
热议问题