How to Change Time Zone on MySQL Server?

Learn via video courses
Topics Covered

In some cases, it is required to change the MySQL time zone of the MySQL server for data and application syncing according to the time zone requirement of the customers and employees.

Using the Set GLOBAL Command

For the setting the GLOBAL time_zone variable to GMT - 6:00 hrs, you have to log into the MYSQL server after that run the command given below:

You must mention GMT offset for your given time in the command mentioned above. And our time zone is GMT - 6:00 hrs in the above example. You can run the command given below to check your time zone.

Output: Using the Set GLOBAL Command

Time zones can be specified in place of the offsets. For this purpose, you have to download the MySQL time zones and then install it on your server.

Using the Set Session Command

We can also set time Zones values session-specific. For this, you have to login into the MySQL server and run the command given below so that you can set the timezone variable that is session-specific to GMT - 6:00 hrs

You have to enter the GMT offset for your MySQL time zone in the command mentioned above. And our time specified time zone is GMT - 6:00 hrs. You can run the command given below to check your time zone

Output: Using the Set GLOBAL Command

Edit my.cnf file

MySQL time zone can also be set by the server configuration file named my.cnf. In the terminal open the file.

Scroll down in the file to reach the [mysqld] section. And there is a line similar to the line given below:

Now modify the ‘+00:00’ into the GMT offset of your time zone, like ‘-6:00’ If the [mysqld] section is not there in your my.cnf file, then add the code given below in your file.

For applying the modifications you have to restart the MySQL server.

Change MySQL Server Time Zone in cPanel

To setMySQL Server timezonein cPanel you have to follow the steps given below:

  1. First of all, you have to log into cPanel WHM.
  2. Select the server configuration option from the list. If you are unable to find it, then you can also search for it in the left pane.
  3. Choose the option Server Time.
  4. From the drop-down list, choose the required time zone.
  5. Select the option Change Timezone button. And according to your selected value, there is an update of value at the current time. Click on the ‘Sync time with Time Server’ button if you feel that an incorrect value is shown.
  6. If it asks for a server reboot, then do it from WHM.

Conclusion

  • We can sync MySQL time zone for data/application by changing it.
  • Set GLOBAL time_zone can be used for setting the global time zone.
  • We can also set the session-specific time zone by using the Set time_zone command.
  • We can also set the MySQL time zone by editing the [mysqld] section of the my.cnf file.
  • And cPanel can also be used for setting the MySQL time zone.