Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Set Session Time Zone While Connecting to Mysql #13663

Open
wants to merge 2 commits into
from

Conversation

Projects
None yet
4 participants

azitabh commented Jan 10, 2014

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.

Contributor

dmathieu commented Jan 10, 2014

Could you add tests please?

azitabh commented Jan 12, 2014

@dmathieu : I have added test cases. Please have a look.

azitabh commented Feb 12, 2014

Test case is failing with the following message:
I, [2014-01-12T19:00:28.467472 #17019] INFO -- : localhost:11211 failed (count: 1) Timeout::Error: execution expired
W, [2014-01-12T19:00:28.467574 #17019] WARN -- : localhost:11211 is down

Any help why did this happen?

Member

maclover7 commented Jan 10, 2016

Please address failing tests on Travis CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment