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

  • Posted 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?


Submit an 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

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

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> <br>