我刚刚发现 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
最佳答案
我认为没有任何地方可以列出它们,但我检查了 ActiveRecord 的 ConnectionAdapters。请记住,选项会更改您使用的数据库,但这已在 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 选项。
关于ruby-on-rails - database.yml 的所有可能键是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33611849/