3

I have installed mysql in my linux server. My server timezone is UTC but mysql timezone in EDT. Now i want to change mysql timezone to UTC.

when i run date in linux command, it shows Fri Nov 6 09:25:01 UTC 2015

when i run select now() in mysql,it shows 2015-11-06 04:25:26.

So how to change EDT to UTC in mysql.

Note : i m using mysql workbench.

MMMMS
  • 2,179
  • 9
  • 43
  • 83

3 Answers3

1

Set you MySQL timezone :-

SET GLOBAL time_zone = '+8:00';
SET GLOBAL time_zone = 'Europe/Helsinki';
SET @@global.time_zone='+00:00';

For check timezone :-

SELECT @@session.time_zone;

location of MySQL configuration file :-

/etc/mysql/my.cnf
Abhishek Sharma
  • 6,689
  • 1
  • 14
  • 20
0

You can try like this:

SELECT CONVERT_TZ(NOW(), @@session.time_zone, '+00:00') 

SQL DEMO and UTC CURRENT TIME

Refer the CONVERT_TZ function.

CONVERT_TZ() converts a datetime value dt from the time zone given by from_tz to the time zone given by to_tz and returns the resulting value.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0

If all you care about is the current time, you don't have to do any conversions or worry about time zones. Just use the appropriate function.

  • NOW() returns the current local time.
  • UTC_TIMESTAMP() returns the current UTC time.

See Date and Time Functions in the MySQL documentation.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • i am using select now() in many place in my application so i should change the mysql timezone to UTC. – MMMMS Nov 06 '15 at 17:50
  • That's another way to do it, sure. But I would be very careful to examine all the places you are doing it. It's not so much the functions that matter, but if you've been writing local time data to your tables and now you start writing UTC data instead, then the mismatch will be a big problem. Think about how to convert existing data first. – Matt Johnson-Pint Nov 06 '15 at 17:54