Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Set Session Time Zone While Connecting to Mysql #13494

Open
azitabh opened this Issue · 6 comments

6 participants

@azitabh

Mysql sets the time zone for all the connections as SYSTEM which is the time zone of the system where mysql-server is running. In my case it is +05:30. It stores all the values in UTC while it accepts and returns all values in the timezone set as session time_zone.

Default timezone for rails4 is :local whereas AR default for rails4 is UTC . So when I set a timestamp field by doing Time.now, AR converts the time into UTC and sends it to Mysql. Mysql assumes the incoming value to be in +05:30 and hence converts it to UTC before storing. So, the conversion to UTC is happening twice.

This problem can be solved by letting AR know what Mysql session time_zone is.
config.active_record.default_timezone = :local

But the problem is if mysql server is to be moved to a separate machine with different time zone setting, our rails application needs to aware of this change and config.active_record.default_timezone must be changed accordingly for a consistent behavior.

This dependency can be removed if AR sets the session time_zone to whatever is set as config.active_record.default_timezone while connecting to the mysql server.
It can be done at the same time when AR sets variables like wait_timeout and etc.

Please point out if I am missing something.

@eric-chahin

Aaron and I are taking this one!

@azitabh

@eric-chahin you can have a look at #13663

@rails-bot
Collaborator

This issue has been automatically marked as stale because it has not been commented on for at least
three months.

The resources of the Rails team are limited, and so we are asking for your help.

If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions.

@azitabh azitabh added the stale label
@azitabh

I thought this was being worked upon.

@eric-chahin

@azitabh My apologies. I should have posted here that we did not end up working on this issue, and I can no longer work on any OSS project due to a company contract I recently signed.

@halida

I think this feature is needed, rails timezone is not always same with database timezone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.