How to Change the MySQL Time Zone on an Ubuntu Server

If you wish to explicitly set the time zone for your MySQL running on an Ubuntu Server, here is how to do it.

First open your global MySQL my.cnf configuration file:

sudo nano /etc/mysql/my.cnf

Scroll down the file to location the [mysqld_safe] section. Add the following line:

timezone = GMT

Obviously you would set it to what you wanted to use, be it UTC, GMT+2 or whatever. Save your changes and restart MySQL:

sudo service mysql restart

Done.

(You can check by creating a table with a timestamp column and then inserting a record with NOW() as the value. This should then show up correctly when queried.)

You might also enjoy:

About Craig Lotter

Craig Lotter is an established web developer and application programmer, with strong creative urges (which keep bursting out at the most inopportune moments) and a seemingly insatiable need to love all things animated. Living in the beautiful coastal town of Gordon's Bay in South Africa, he games, develops, takes in animated fare, trains under the Funakoshi karate style and for the most part, simply enjoys life with his amazing wife and daughter. Oh, and he draws ever now and then too.
This entry was posted in MySQL, Ubuntu and tagged , , , , . Bookmark the permalink.
    blog comments powered by Disqus