Is there an exhaustive list of MySQL Time Zones?
It seems that the valid values for time_zone
in MySQL settings are dependent on the host Operating System but I have been unable to find a list of possible values.
I need the time to show Calgary local time.
An exhaustive list of timezones can be downloaded from MySQL's website as database tables that get imported into MySQL server.
For Calgary time you can specify UTC offsets as
I have gone ahead and created a gist.
https://gist.github.com/4134305https://gist.github.com/kinjal/9105369
I hope people find it useful.
It should be noted that the MySQL timezone variable's default setting is SYSTEM at MySQL startup. The SYSTEM value is obtained from the the operating system's GLOBAL time_zone environment variable.
MySQL's default timezone variable can be initialised to a different value at start-up by providing the following command line option:
Alternatively, if you are supplying the value in an options file, you should use the following syntax to set the variable:
If you are a MySQL SUPER user, you can set the SYSTEM time_zone variable at runtime from the MYSQL> prompt using the following syntax:
MySQL also supports individual SESSION timezone values which defaults to the GLOBAL time_zone environment variable value. To change the session timezone value during a SESSION, use the following syntax:
In order to interrogate the existing MYSQL timezone setting values, you can execute the following SQL to obtain these values:
The only answer: http://timezonedb.com/download
Text to make this answer valid
By default, (at least on Debian-based installations) no time zone data is loaded into MySQL. If you want to test if they are loaded, try executing:
If it returns a
DATETIME
(in this case2012-06-07 08:00:00
), you have time zones loaded. If it returnsNULL
, they aren't. When not loaded, you are limited to converting using offsets (e.g.+10:00
or-6:00
).This should work fine in many cases, but there are times when it is better to use named time zones, like for not worrying about daylight savings time. Executing the following command loads the time zone data from the system (Unix-only. I'm not sure what the equivalent Windows command would be):
If you need to continually rely on MySQL time zones, the above command should be executed every time the system time zone is updated. You could also just add it to a weekly or monthly cron job to do it for you automatically.
Then, to view a list of time zones, just do the following:
Note, the time zone info takes up about 5 MB in MySQL. If you ever want to un-load the timezone info, just execute the following and restart MySQL:
Do not
DROP
these tables or bad things will happen.Edit:
Based on a user comment below, if you want to have the timezones automatically updated when you update the system, you first need to allow root to log in without being prompted for a password.
MySQL >= 5.6.6
Execute the following [source]:
MySQL < 5.6.6
Create a
~/.my.cnf
file (if it doesn't exist yet) and add the following:Then execute
chmod 600 ~/.my.cnf
to make sure nobody else can read it.Update script
Add the following script to crontab to be executed once per day:
Remove the
echo
lines if you don't want any output.Note: This is (mostly) untested. Let me know if you have any issues and I'll update this answer.
From the MySQL 5.7 documentation (emphasis mine):
It should be noted that the MySQL timezone variable's default setting is SYSTEM at MySQL startup. The SYSTEM value is obtained from an operating system setting (e.g. from the file that is referenced by the symlink
/etc/localtime
)MySQL's default timezone variable can be initialised to a different value at start-up by providing the following command line option:
Alternatively, if you are supplying the value in an options file, you should use the following syntax to set the variable:
If you are a MySQL SUPER user, you can set the SYSTEM time_zone variable at runtime from the MYSQL> prompt using the following syntax:
MySQL also supports individual SESSION timezone values which defaults to the GLOBAL time_zone environment variable value. To change the session timezone value during a SESSION, use the following syntax:
In order to interrogate the existing MYSQL timezone setting values, you can execute the following SQL to obtain these values:
For what it's worth, I simply googled mysql time_zone configuration valid values and looked at the first result.