mysql convert_tz命令返回NULL

pge*_*e70 4 mysql debugging null

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

mysql --version
mysql  Ver 14.14 Distrib 5.6.11, for osx10.7 (x86_64) using  EditLine wrapper 
Run Code Online (Sandbox Code Playgroud)

我阅读了手册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
Run Code Online (Sandbox Code Playgroud)

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

neo*_*ate 16

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

$ mysql_tzinfo_to_sql /usr/share/zoneinfo > tzinfo.sql
Run Code Online (Sandbox Code Playgroud)

找到有问题的行,在我的例子中它是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');
Run Code Online (Sandbox Code Playgroud)

将其更改为:

INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES (@time_zone_id, 0, 0, 0, 'UNSET');
Run Code Online (Sandbox Code Playgroud)

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

$ cat tzinfo.sql | mysql -u root mysql
Run Code Online (Sandbox Code Playgroud)

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

  • `mysql_tzinfo_to_sql/usr/share/zoneinfo | 必须设置sed -e"s /本地时区 - 请参阅zic手册页/本地/"| mysql -u root mysql`似乎在一行中做同样的事情.在ubuntu 14.04上为我工作. (4认同)