How to Change MySQL Server Time Zone in Dedicated Server ?

To change the time zone of your MySQL server, please follow the below steps.

1) Login to your server via SSH as root user.

2) You can find current MySQL server time zone via executing the following command.

mysql -e “SELECT @@global.time_zone;”

The output of the above command is something similar to the following:

@@global.time_zone

SYSTEM

Here we can see that the MySQL time zone is set as “System”. Which means current MySQL time zone depends on the system time.

By default, MySQL time zone will be set to the server’s time zone. If you are interested in changing MySQL Time zone you can edit /etc/my.cnf configuration file.

3) You can check the server’s current time using following command:

$ date

The date command will give back something similar to the following:

Thu Apr 18 21:42:04 IST 2019

4) You can check current timestamp using in MySQL by executing the following command:

$ mysql -e “SELECT NOW();”

The command will give back something like:

NOW()

2019-04-18 21:42:04

5) You can change your MySQL time zone by editing MySQL configuration file (/etc/my.cnf). You need to open the config. file using your favorite text editor.

vi /etc/my.cnf

Then add the time zone details to the bottom of the configuration file. For example:

default-time-zone = ‘-06:00’

6) Run the following command to check if time zone has changed.

mysql -e “SELECT @@global.time_zone;”

7) You should also check with the NOW function.

mysql -e “SELECT NOW();”