Rails 重新连接中的 database.yml 设置为 true 或 false [英] database.yml in Rails reconnect set to true or false

查看:66
本文介绍了Rails 重新连接中的 database.yml 设置为 true 或 false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

database.yml 中,Rails 3 和 4 上 reconnect 的默认设置是 false.什么是通用设置,在什么情况下我们应该将其设置为true?谢谢.

In database.yml, the default settings for reconnect on Rails 3 and 4 is false. What is the common setting, and in what circumstances we should set it to true? Thanks.

推荐答案

您可以将其设置为 true.这个选项是在 Rails 2.3 中引入的

You can set it true. This option is introduced in Rails 2.3

MySQL 在其连接中支持重新连接标志 - 如果设置为 true,则客户端将尝试重新连接到服务器,然后在连接丢失的情况下放弃.您现在可以在 database.yml 中为 MySQL 连接设置 reconnect = true 以从 Rails 应用程序获取此行为.

MySQL supports a reconnect flag in its connections - if set to true, then the client will try reconnecting to the server before giving up in case of a lost connection. You can now set reconnect = true for your MySQL connections in database.yml to get this behavior from a Rails application.

Rails 团队将此选项默认设置为false",因为他们不想更改现有应用程序的行为.

Rails team set this option default as 'false' because, they don't want to change the behavior of existing applications.

但是如果我们设置reconnect = true,就会有一些副作用.它不是事务安全的.MySQL 文档事实明确指出自动重新连接功能会影响事务.

But some side effects are there if we set reconnect = true. It is not transaction-safe.The MySQL documentation in fact explicitly states that the auto-reconnect feature affects transactions.

回滚所有活动事务并重置自动提交模式.

Any active transactions are rolled back and autocommit mode is reset.

未针对此问题编写的应用程序很容易崩溃.该文档还列出了由自动重新连接功能引起的许多其他副作用,所有这些副作用都可能导致未编写的应用程序无法预测行为,从而无法正常运行或失败.

Applications that are not written to deal with this could easily break. The documentation also lists a number of other side effects caused by the auto-reconnect feature, all of which could cause applications not written to anticipate the behavior to function incorrectly or fail.

检查:

rails 2.3 发行说明

mysql-重新连接值不粘

查看这个 StackOverflow 问题

这篇关于Rails 重新连接中的 database.yml 设置为 true 或 false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆