I am trying to import time zones according to this document: http://dev.mysql.com/doc/refman/5.7/en/mysql-tzinfo-to-sql.html.
When I try hitting even first command throu
The
There were fatal errors during processing of zoneinfo directory 'tz_dir'
error message means that the directory cannot be read (not enough access rights or not even exists).
Knowing that the mysql_tzinfo_to_sql
program is just a tool that converts a bunch of timezone files into an SQL script that you can use to install the time zones for mysql, your task is the following:
These steps can be performed on different computers if you transfer the files between them. For example, I installed the timezones on a machine where the mysql installation was not complete, that is, mysql_tzinfo_to_sql
was not available and I wasn't able to install it either.
In such a case you can combine the following steps:
mysql_tzinfo_to_sql
is not available on the computer where your mysql database resides then find a computer where mysql_tzinfo_to_sql
is already installedzoneinfo
folder available on that computer. It is just a bunch of files in different folders so you can transport them in a gzip file from one computer to the other. In a normal mysql installation this folder should exist but maybe your installation is not complete, su just get it from anywhere.execute the mysql_tzinfo_to_sql
command to create an SQL script like this:
mysql_tzinfo_to_sql path-to-your-zoneinfo-folder >install_mysql_zoneinfo.sql
move the created SQL script to the computer where your mysql database resides *
execute the script like this:
mysql --user=root --password=abc123 mysql <install_mysql_zoneinfo.sql
Adjust the username and password if needed and your script will be executed. This will fill up the timezone-related tables with the appropriate values and you will be able to use them:
SELECT convert_tz(NOW(),'UTC','Australia/Melbourne');
-h <hostname>
command line argument to the subsequent script-executing program and you will not have to copy the SQL script to the target machine.I also had this issue this morning while trying to populate the timezone tables on our production server (using CentOS).
I worked around this problem by exporting the table creation script from my development computer (populating the tables on Windows simply requires to download the tables and copy them in the proper directory).
I tweaked the creation script a little bit and it is now working for me:
I cannot post it in my answers since the script is too long.
https://drive.google.com/file/d/0B7iwL5F-hwr_YkItRXk2Z1VZdlE/view?usp=sharing
Here's a version with the comment (but it doesn't seems to work, so use the version without comments).
https://drive.google.com/file/d/0B7iwL5F-hwr_dWdjTDREcXNHQmM/view?usp=sharing
The script should take no more than a few second to run. You'll probably need to use the root
user to be able to run it.
You can use this query in order to validate the installation:
SELECT CONVERT_TZ(CURRENT_DATE(),'UTC','America/Montreal');
If it returns NULL
instead of a datetime
, it means the script failed.
Good success