mysql convert_tz命令返回NULL

时间:2013-07-29 00:00:29

标签: mysql debugging null

我有一个问题,在mysql中返回null的convert_tz。

mysql --version
mysql  Ver 14.14 Distrib 5.6.11, for osx10.7 (x86_64) using  EditLine wrapper 

我阅读了手册http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html 我跑了这个命令:     bash-3.2#mysql_tzinfo_to_sql / usr / share / zoneinfo | mysql -u root -p mysql     输入密码:警告:无法加载'/ usr / share / zoneinfo / + VERSION'作为时区。跳过它。

Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh87' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh88' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh89' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh87' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh88' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh89' as time zone. Skipping it.
ERROR 1406 (22001) at line 38916: Data too long for column 'Abbreviation' at row 1

然后,使用mysql我运行此命令。     SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','EST'); 返回null。 我可以确认mysql.time_zone_transition_type表有GMT和EST条目。

2 个答案:

答案 0 :(得分:16)

解决此问题的另一种方法是,将mysql_tzinfo导出到文本文件进行编辑:

$ mysql_tzinfo_to_sql /usr/share/zoneinfo > tzinfo.sql

找到有问题的行,在我的例子中是第38982行,这是从第38982行到38984行的分割查询:

INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST,    Abbreviation) VALUES (@time_zone_id, 0, 0, 0, 'Local time zone must be set--see zic manual page');

将其更改为:

INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES (@time_zone_id, 0, 0, 0, 'UNSET');

保存文件并将其插入mysql数据库:

$ cat tzinfo.sql | mysql -u root mysql

来源:http://dev.mysql.com/doc/refman/4.1/en/time-zone-support.html
使用MacOS 10.9.3,MySQL 5.6.15

进行测试

答案 1 :(得分:0)

**更新,我通过使用linux框来创建sql文件:mysql_tzinfo_to_sql / usr / share / zoneinfo,然后将此文件导入我的mac mysql。