Oct 17, 2018

Set MySQL to use a different timezone

While you can tell mysql to use use a different timezone


but you have to then maintain it:

"Loading the time zone information is not necessarily a one-time operation because the information changes occasionally. When such changes occur, applications that use the old rules become out of date and you may find it necessary to reload the time zone tables to keep the information used by your MySQL server current. See the notes at the end of this section."

How to set the time zone only for MySQL:

a. Load the time zone tables. See https://dev.mysql.com/doc/refman/5.7/en/mysql-tzinfo-to-sql.html for instructions. 

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -uroot -p mysql

b. Set the time zone in the [mysqld] section of my.cnf:

default_time_zone=UTC (See https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_default-time-zone)

c. Restart MySQL and check that UTC is set as the time zone when MySQL starts:

mysql> SHOW VARIABLES LIKE 'time_zone';
You can ask MySQL to use System and change system's timezone.

$ date
Wed Oct 17 10:37:13 EDT 2018
$ cd /etc
$ ls localtime
$ sudo rm -f localtime 
$ sudo ln -s /usr/share/zoneinfo/UTC localtime
$ date
Wed Oct 17 14:37:58 UTC 2018