How to change default time zone in MySQL

To change default time zone in MySQL , you must have the root privilege to the server. We have to edit the MySQL configuration file to change the time zone of MySQL server from its default.

please note that We can’t change the time zone for a single DB, it’s a global change.

By default the MySQL server time is same as the Server time. We can check this by using the following commands:

To check the server time

date

To check MySQL server time

mysql -e “SELECT NOW();”

mysql-default-time

How to change the MySQL server time from command line:

We can change this by adding the following directives to the MySQL configuration file.

  1.  Log into server as root user.
  2. To check MySQL’s current time zone settings, execute the following command:
mysql -e “SELECT @@global.time_zone;”

It means MySQL is using server SYSTEM default time. To change this, you need to add the following directive into the MySQL conf file.

 “default-time-zone”

1- Open MySQL conf by using your favorite editor;

vi /etc/my.cnf
====
default-time-zone = '-06:00'
====

2- Restart MySQL

service mysql restart

That’s it!!! Now check the current MySQL server time by using the command mysql -e
“SELECT NOW();”.