Change Google Cloud SQL CURRENT_TIMESTAMP time zone?
Asked Answered
B

2

14

I'm using CURRENT_TIMESTAMP in Google Cloud SQL and according to Google, it returns the server's current time.

Currently, with the time that it returns, it looks like the server's at UTC -1 (i.e., in the Atlantic Ocean). This is not very helpful.

How do I change the timezone and have it display the right time (i.e., a time zone of my own choosing) whenever I call CURRENT_TIMESTAMP?

Backset answered 21/10, 2014 at 17:23 Comment(0)
D
19

There is a new way to to change Google cloud SQL time zone https://mcmap.net/q/829841/-google-cloud-sql-and-time-zones

Instructions: https://cloud.google.com/sql/docs/mysql-flags

  1. Go to the Google Developers Console.
  2. Create a new Developers Console project, or open an existing project by clicking on the project name.
  3. In the sidebar on the left, click Storage > Cloud SQL to show a list of Cloud SQL instances for the project.
  4. Open your instance and click Edit. If you need to create a new instance, click New instance.
  5. Scroll down to the MySQL Flags section.
  6. Choose flags from the drop-down menu and set their values.
  7. Click Save. You can check your flags under MySQL Flags on the overview page.
Ducharme answered 2/7, 2015 at 0:34 Comment(2)
This is awesome! Thanks.Caswell
I do not see the time_zone flag for the system zone available there. It has default_time_zone only, which is the global zone.Chauvin
L
1

Cloud SQL sets the system time as UTC.

You can set the timezone for an individual session with a statement like:

SET @@session.time_zone='-07:00';

You can use named (and daylight savings aware) timezones such as "US/Pacific" if you first set up the timezone table by running a system command like:

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -h YOUR_INSTANCE_IP -u root -p mysql
Lowkey answered 29/10, 2014 at 21:45 Comment(1)
Just some thoughts on how one might run mysql_tzinfo_to_sql on a cloud SQL instance. mysql_tzinfo_to_sql doesn't appear to exist, but /usr/share/zoneinfo does. It looks like one could apt install mysql-server-5.5 (the Debian package that contains mysq_tzinfo_to_sql). I'm not sure how to clean up after this and destroy the cloud shell files though.Tulle

© 2022 - 2024 — McMap. All rights reserved.