How to populate zone tables in mysql database within ubuntu with xampp

后端 未结 2 1735

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

2条回答
  •  庸人自扰
    2021-01-21 19:37

    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:

    • obtain the timezone files from somewhere
    • execute mysql_tzinfo_to_sql to create an SQL script from those files
    • execute that SQL script in your mysql database.

    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:

    • if 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 installed
    • make the zoneinfo 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

    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'); 
    
    • if you can reach the mysql database from the computer where the SQL script was generated then it's enough to add the -h command line argument to the subsequent script-executing program and you will not have to copy the SQL script to the target machine.

提交回复
热议问题