Report this

What is the reason for this report?

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

Posted on May 2, 2014

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?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

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

sudo /etc/init.d/mysql restart

What OS are you using? You can check the system timezone on Ubuntu or Debian with: <br> <br><pre> <br>cat /etc/timezone <br></pre> <br> <br>and you can set it to something else using: <br> <br><pre> <br>sudo dpkg-reconfigure tzdata <br></pre> <br> <br>You can check the mysql timezone with: <br> <br><pre> <br>SELECT @@global.time_zone, @@session.time_zone; <br></pre> <br> <br>You can check the php timezone with: <br> <br><pre> <br>$tz = date_default_timezone_get(); <br>echo $tz; <br></pre> <br> <br>Both php and mysql should have defaulted to system time, but if they aren’t respecting that for some reason you can change them. <br> <br>In mysql: <br> <br><pre> <br>SET GLOBAL time_zone = timezone; <br></pre> <br> <br>In php: <br> <br><pre> <br>date_default_timezone_set(‘timezone’); <br></pre> <br> <br>See also: <br> <br>https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html <br>http://php.net/manual/en/function.date-default-timezone-set.php

Thanks Andrew! <br>It was helpful information. <br>Thanks again.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.