Mysql – I can’t find time zone tables in sys database of MySQL

MySQLmysql-5.7timezone

For my Django application, I had to set the time zone to UTC, however I am not able to set it as I couldn't find any tables related to time zone in the system database.

How do I get those? the scripts available in here https://dev.mysql.com/downloads/timezones.html only relates to loading of data in the tables and not creating them.

  • MySQL Version: 5.7
  • OS: Windows

Best Answer

I used to face the same issue as you and I resolved it by following these quick steps.

Please follow below:

Environment:

  • MySQL Version: 5.7

  • OS: Windows 10 (64 bit)

Steps:

  • Download the package that contains the data files of pre-built time zone tables. You can download here https://dev.mysql.com/downloads/timezones.html
    • timezone_2018e_posix_sql.zip - POSIX standard for MySQL version 5.7
  • Extract the downloaded package, you will then have a file named timezone_posix.sql
  • Open a command line in the root directory of MySQL. Ex: On my computer this is "C:\Program Files\MySQL\MySQL Server 5.7\bin"
  • Run the command mysql -u root -p to login to MySQL with root access and then enter password.
  • Run the command show databases; to view all database. You will see a database named mysql. You need to insert data into the mysql database
    • Run the command use mysql;
  • Finally, you can insert data by issuing the command source *path timezone_posix.sql*.

After inserting the timezone data, you can test by issuing the following query:

 SELECT CONVERT_TZ('2018-07-02 14:46:46','utc','America/Los_Angeles')

If the result is not null, you're successful!!!