Robert Johnstone
Robert Johnstone

Reputation: 5371

MySQL 'select now()' out of sync with linux 'date'

(I hope someone can solve this quick sharp because this is on my production server)

It's really in the title. I thought mysql got its datetime from the machine it is installed on... well I was wrong!

currently its 2.30pm

linux says its 2.30pm

MySQL says its 9.30am?!?!

What should I do because it's date stamping everything in the database with the wrong time?

Upvotes: 3

Views: 4215

Answers (4)

user2016685
user2016685

Reputation: 21

Please follow the commands:

mv /etc/localtime /etc/localtime_original
ln -s /usr/share/zoneinfo/Asia/Singapore /etc/localtime
service mysqld restart

verify and it should be fine now.

Upvotes: 2

caf
caf

Reputation: 239071

It sounds like you want to set the mysql system time zone to UTC. Add the line:

timezone=UTC

To the [mysqld_safe] section of /etc/my.cnf, and restart mysqld.

Upvotes: 1

Robert Johnstone
Robert Johnstone

Reputation: 5371

(Someone posted something very similar to this and then deleted it. Sorry I couldn't understand your answer initially, I just didn't understand the context)

Change the timezone of the server from the command line with:

# export $TZ=Europe/London

and then restart mysql with (RedHat/Fedora/CentOS):

# service mysqld restart

(Deban/Ubuntu):

# /etc/init.d/mysql restart

Upvotes: 0

Nanne
Nanne

Reputation: 64409

Could it be a problem with you locale? Maybe one of the two calculates the +x from your locale, but the other just uses the system-time?

Upvotes: 0

Related Questions