database.yml的所有可能键都是什么

时间:2015-11-09 14:55:32

标签: ruby-on-rails ruby-on-rails-4 activerecord

我刚刚发现reconnect: true文件中可以使用database.yml配置选项。 还有哪些其他可能的配置选项?所有选项都有完整的参考资料吗?

已知的关键示例:

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: foo
  password: bar
  reconnect: true
  socket: /var/sock/thing.sock

development:
  <<: *default
  database: app_development

1 个答案:

答案 0 :(得分:10)

我认为没有任何地方可以列出它们但我查看了ActiveRecord的ConnectionAdapaters。请记住,选项会更改您使用的数据库,但这已在MySQL连接适配器中列出。

MySQL的选项列表

:host - Defaults to "localhost".
:port - Defaults to 3306.
:socket - Defaults to "/tmp/mysql.sock".
:username - Defaults to "root"
:password - Defaults to nothing.
:database - The name of the database. No default, must be provided.
:encoding - (Optional) Sets the client encoding by executing "SET NAMES <encoding>" after connection.
:reconnect - Defaults to false (See MySQL documentation: http://dev.mysql.com/doc/refman/5.7/en/auto-reconnect.html).
:strict - Defaults to true. Enable STRICT_ALL_TABLES. (See MySQL documentation: http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html)
:variables - (Optional) A hash session variables to send as SET @@SESSION.key = value on each database connection. Use the value +:default+ to set a variable to its DEFAULT value. (See MySQL documentation: http://dev.mysql.com/doc/refman/5.7/en/set-statement.html).
:sslca - Necessary to use MySQL with an SSL connection.
:sslkey - Necessary to use MySQL with an SSL connection.
:sslcert - Necessary to use MySQL with an SSL connection.
:sslcapath - Necessary to use MySQL with an SSL connection.
:sslcipher - Necessary to use MySQL with an SSL connection.

Rails ActiveRecord适配器的github,https://github.com/rails/rails/tree/master/activerecord/lib/active_record/connection_adapters

编辑: 添加@pjrebsch在下面评论的内容。您还可以在Mysql2 gem's Readme

上查看MySQL选项