How to set the default time zone in mysql?

Divyesh Patel asked
php mysql core

How to get current time of system using mysql query.

I try out NOW() function and it’s return

2017-11-07 05:36:16 

but my system time is

2017-11-07 11:06:16.

How to get to exact system time?

How to implement in mysql query?


There are a number of ways to do this according to the MySQL documentation.

Following the documentation, open your my.cnf file (MySQL configuration). On Linux, that is usually under /etc/my.cnf or /etc/mysql/my.cnf. On Windows, see other places to look.

Add this line and restart MySQL.


Replace [TIMEZONE] with the timezone you prefer to use.

The value can be given as a string indicating an offset from UTC, such as ‘+10:00’ or ‘-6:00’.

Share This
Posted in: