Saturday, 5 March 2016

Update Time Zone In MySQL Database Centos

First check on hardware node time zone . Hardware time zone should be same as mysql


1. Login to mysql database server with root and check current time zone


mysql -u root -p


mysql> select now();          ------>>>    # to chekc time zone

\q


2. Check time_zone* tables in mysql db. if they are empty fill them using following command


# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql -p'dbpassword'


Enter mysql password:

some file will skipeed... ignore it


3. Again login to mysql:


mysql -u root -p

mysql> select now();

mysql> SET GLOBAL time_zone = "Asia/Calcutta";


OR

mysql> SET GLOBAL time_zone = "Asia/Kolkata";

mysql> select now();

To check mysql time zone :
show variables like '%time_zone%';

mysql> \q


OR


To check mysql time zone :
show variables like '%time_zone%';
SELECT @@global.time_zone, @@session.time_zone;
select now();

To change time zone in MySQL :
check system date and time
# date
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql -p'!P4erere04d#'
SET GLOBAL time_zone = "Asia/Kolkata";
select now();

OR

vim /etc/my.cnf

default-time-zone='+05:30'

:wq

service mysqld restart

No comments: