-_rlza
Last Updated: February 25, 2016
·
2.082K
· celc

Setting up MySQL timezones under OSX.

I've been getting exceptions in Django because MySQL isn't setup with timezone tables by default. Which is supposed to be done with:

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

However mysql_tzinfo_to_sqlgenerates an error message inline if system times aren't set an insert gets the value Local time zone must be set--see zic manual page which causes an error (assuming you're operating in strict mode as you should) because it's too long. In my case localtime was setup correctly, so I'm uncertain why the error would still appear;

$ ls -l /etc/localtime 
lrwxr-xr-x  1 root  wheel  34 Jan  4 00:36 /etc/localtime -> /usr/share/zoneinfo/Asia/Singapore

So instead we'll need to strip out the offending line:

mysql_tzinfo_to_sql /usr/share/zoneinfo |
sed -e "s/Local time zone must be set--see zic manual page/local/" |
mysql -u root mysql