MySQL – Does Not Follow Ubuntu System Time Zone

dockerMySQLmysql-5.7timezoneUbuntu

An Ubuntu 16.04 server has it's time zone set to America/New_York using the command

sudo timedatectl set-timezone America/New_York

This is confirmed by running the commands

timedatectl status | grep "Time zone"

 Time zone: America/New_York (EST, -0500)

date +%Z

EST

However MySQL thinks that the system's time zone is still UTC. MySQL 5.7 server (running within a docker container) has been restarted befpre querying for the MySQL timezone

Output of MySQL Query show global variables like '%time_zone'

system_time_zone UTC
time_zone SYSTEM

Did something go wrong?

Best Answer

You say you run mysql inside docker. Docker needs timezone as an environment variable as follows:

Add the following to mysql startup command in docker:

-e TZ='America/New_York' 

https://github.com/docker-library/mysql/issues/320