Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql convert_tz command returns NULL

I have a problem with convert_tz returning null in mysql.

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

i read the manual http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html i ran this command: bash-3.2# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql Enter password: Warning: Unable to load '/usr/share/zoneinfo/+VERSION' as time zone. skipping it.

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

then, using mysql i ran this command. SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','EST'); which returns null. I can confirm the mysql.time_zone_transition_type table has GMT and EST entries.

like image 969
pgee70 Avatar asked Dec 03 '22 22:12

pgee70


1 Answers

Another way to get around this problem, export the mysql_tzinfo to a textfile for editing:

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

Find the problematic line, in my case it was line 38982, which was a splitted query from line 38982 to 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');

Change it to:

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

Save the file and insert it to your mysql database:

$ cat tzinfo.sql | mysql -u root mysql

Source: http://dev.mysql.com/doc/refman/4.1/en/time-zone-support.html
Tested with MacOS 10.9.3, MySQL 5.6.15

like image 96
neonmate Avatar answered Dec 14 '22 12:12

neonmate