Different times in mysql and the server! How can they be equal?

Posted May 2, 2014 9.6k views
I'm running nginx php and mysql in the same droplet but php and mysql gives different times. Mysql is approximately 8 hours before the php time. Actually, I need only to have the UTC times both in php and mysql. What should I do?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers
What OS are you using? You can check the system timezone on Ubuntu or Debian with:

cat /etc/timezone

and you can set it to something else using:

sudo dpkg-reconfigure tzdata

You can check the mysql timezone with:

SELECT @@global.time_zone, @@session.time_zone;

You can check the php timezone with:

$tz = date_default_timezone_get();
echo $tz;

Both php and mysql should have defaulted to system time, but if they aren't respecting that for some reason you can change them.

In mysql:

SET GLOBAL time_zone = timezone;

In php:


See also:
Thanks Andrew!
It was helpful information.
Thanks again.

After reconfiguration of system timezone you might need to restart mysql to make the changes take effect

sudo /etc/init.d/mysql restart