5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby on Railsにおけるdatabase.ymlの設定方法

Posted at

サンプルコード

app/config/database.yml
default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: <%= ENV['RAILS_DATABASE_USER'] %>
  password: <%= ENV['RAILS_DATABASE_PASSWORD'] %>
  socket: /var/lib/mysql/mysql.sock

development:
  <<: *default
  database: rails-devise-ja-development
test:
  <<: *default
  database: rails-devise-ja-test
production:
  <<: *default
  database: rails-devise-ja
  username: <%= ENV['RAILS_DATABASE_USER'] %>
  password: <%= ENV['RAILS_DATABASE_PASSWORD'] %>

※サンプルコードのように設定を引き継がせることも可能

設定項目

adapter: 使用するデータベース種類
encoding: 文字コード
reconnect: 再接続するかどうか
database: データベース名
pool: コネクションプーリングで使用するコネクションの上限
username: ユーザー名
password: パスワード
host: MySQLが動作しているホスト名

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?