ruby-on-rails – database.yml的所有可能键

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – database.yml的所有可能键前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚刚发现在 database.yml文件中可以使用reconnect:true配置选项.
还有哪些其他可能的配置选项?所有选项都有完整的参考吗?

已知的关键示例:

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的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选项

原文链接:https://www.f2er.com/ruby/270364.html

猜你在找的Ruby相关文章