Change the Timezone for MySQL

Change the Timezone for MySQL

Check the current timezone from MySQL:

SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP);
image 3 - Change the Timezone for MySQL

OR

select now();
image 7 - Change the Timezone for MySQL

To check where the timezone is loaded from use:

SELECT @@session.time_zone;
SELECT @@global.time_zone;
image 4 - Change the Timezone for MySQL

If it is set to SYSTEM then it is using either timezone defined inside the my.cnf file or from the OS.

Check my.cnf:

grep time /etc/my.cnf
image 6 - Change the Timezone for MySQL

Check OS timezone:

date
image 5 - Change the Timezone for MySQL

You can set a different timezone on the OS and it will apply to mysqld after service restart, or to use different timezones for OS and for MySQL, set:

SET GLOBAL time_zone = '+8:00';
SET GLOBAL time_zone = 'Europe/Helsinki';
SET @@global.time_zone = '+00:00';
SET @@session.time_zone = "+00:00";

*Replace +8:00 and Europe/Helsinki with your timezone.

to make the changes permanent:

nano /etc/my.cnf

and under [mysqld] section add:

default-time-zone = "+00:00"

save the file and restart mysqld service.

whoami
Stefan Pejcic
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.