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.
You can set it true. This option is introduced in Rails 2.3
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 team set this option default as 'false' because, they don't want to change the behavior of existing applications.
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.
check:
rails 2.3 release notes
mysql-reconnect-value-doesnt-stick
see this StackOverflow question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With