如何在 ubuntu 中使用 xampp 填充 mysql 数据库中的区域表

2022-01-14 00:00:00 ubuntu xampp mysql

我正在尝试根据此文档导入时区:http://dev.mysql.com/doc/refman/5.7/en/mysql-tzinfo-to-sql.html.

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 through terminal i.e.

mysql_tzinfo_to_sql tz_dir

它说

There were fatal errors during processing of zoneinfo directory 'tz_dir'

当我跑步时:

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql

然后它返回

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

操作系统: Ubuntu

服务器: XAMPP(具有 mariadb)

Server: XAMPP (having mariadb)

所以,我无法将时区数据导入到 mysql 数据库的时区表中.

So, I am not able to import timezone data into the zone tables of mysql database.

推荐答案

我今天早上在我们的生产服务器(使用 CentOS)上填充时区表时也遇到了这个问题.

I also had this issue this morning while trying to populate the timezone tables on our production server (using CentOS).

我通过从我的开发计算机导出表创建脚本解决了这个问题(在 Windows 上填充表只需要下载表并将它们复制到正确的目录中).

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

脚本的运行时间不应超过几秒钟.您可能需要使用 root 用户才能运行它.

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');

如果它返回 NULL 而不是 datetime,则表示脚本失败.

If it returns NULL instead of a datetime, it means the script failed.

成功

相关文章