Change timezone on MySQL Server on Ubuntu

There are various ways of setting the timezone that the MySQL server uses. To explicitly set the timezone that MySQL uses on Ubuntu, all we have to do is add a line to the MySQL configuration file.

Note that it is usually not necessary to explicitly set the timezone for the MySQL server as MySQL is pretty good at getting the correct timezone from the system. Use the method outlined below only if you have special requirements.

Open a terminal, and run the following command as root:

nano /etc/mysql/my.ini

That will open the MySQL global configuration file. Find the section which is called [mysqld_safe]. It should be pretty close to the top of the configuration file.

Below the entries which are there for that section, add a line like the following to specify the timezone that you want to use:

timezone = GMT

You may add timezones in terms of their difference from GMT such as GMT-5 or GMT+8 and so on.

After you have done that, save and close the configuration file. The final step is to restart the MySQL server using:

service restart mysql

For more information on restarting the MySQL server, see our Restart MySQL on Ubuntu tutorial.

Check to see if your timezone changes are correct by checking the current time according to MySQL. To do this, execute the following SQL query after logging in to the MySQL client.


That will return the current time and date according to MySQL. If that date and time is still incorrect, you may need to set your system date and time. See how to change timezone on Ubuntu using the Command Line. If all goes well your MySQL time will be correct.

We hope you found this MySQL server tutorial helpful.

Thank Tutorial Arena for This Tutorial.
Show your appreciation with a +1...