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

Boo*_*reg 11 activerecord ruby-on-rails ruby-on-rails-4

我刚刚发现文件中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
Run Code Online (Sandbox Code Playgroud)

Jar*_*red 13

我不认为有任何地方只是列出它们但我检查了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.
Run Code Online (Sandbox Code Playgroud)

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

编辑:添加@pjrebsch在下面评论的内容.您还可以在Mysql2 gem的自述文件中看到MySQL选项

  • 令我惊讶的是,这不是如此成熟和流行的框架的文档的一部分。您正在查看哪个文件以获取此列表?您的链接中有很多代码。 (3认同)