List:General Discussion« Previous MessageNext Message »
From:Daevid Vincent Date:October 5 2010 12:03am
Subject:RE: Any way to change timezone WITHOUT mysqld restart?
View as plain text  
Trust me, I read it. 
 
We had an I18N product at my last company and all our time was stored in
UTC in mySQL and we'd alter it on the fly for each user. This isn't rocket
science. It's done every day in probably many of the sites you visit and
don't even know it.
 
To clarify for you (again):
 

*	
Per-connection time zones. Each client that connects has its own time zone
setting, given by the session
<http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar
_time_zone> time_zone variable. Initially, the session variable takes its
value from the global
<http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar
_time_zone> time_zone variable, but the client can change its own time zone
with this statement: 

	mysql> SET time_zone = timezone;



The current session time zone setting affects display and storage of time
values that are zone-sensitive. This includes the values displayed by
functions such as
<http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#functi
on_now> NOW() or
<http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#functi
on_curtime> CURTIME(), and values stored in and retrieved from
<http://dev.mysql.com/doc/refman/5.1/en/datetime.html> TIMESTAMP columns.
Values for  <http://dev.mysql.com/doc/refman/5.1/en/datetime.html>
TIMESTAMP columns are converted from the current time zone to UTC for
storage, and from UTC to the current time zone for retrieval. 

Don't forget to do this stuff too:
http://dev.mysql.com/doc/refman/5.1/en/mysql-tzinfo-to-sql.html

So if it's not clear by now, you store all your dates/times in UTC (convert
them via some script if you didn't start out that way). Then per web page
connection, you read the user's profile TZ (presumably from the user
session object or some other persistent means), execute that SQL statement
above as one of the first things on the page, and "FM" ensues. All your
properly saved mysql rows will display in the LOCAL "timezone" instead of
UTC. You ALSO have to set the TZ in PHP too don't forget or you'll get
whacky discrepencies.

http://php.net/manual/en/function.date-default-timezone-set.php

There's plenty of info on this out there for using PHP & MySQL if that's
what you're using too...

http://www.ferdychristant.com/blog//archive/DOMM-84NEJN

 

  _____  

From: Bryan Cantwell [mailto:bcantwell@stripped] 
Sent: Saturday, October 02, 2010 5:18 AM
To: Daevid Vincent
Cc: mysql@stripped
Subject: RE: Any way to change timezone WITHOUT mysqld restart?


As a matter of fact I did, the real question is : Did you even read my
email? I said WITHOUT a restart...
The manual states that a restart of the mysqld is required. The reason for
the post to such a list is because on many occasions, user have suggestions
on some workaround for things that do work in spite of what the manual
says. 

On Fri, 2010-10-01 at 15:42 -0700, Daevid Vincent wrote: 

Did you even look at the manual?



http://lmgtfy.com/?q=mysql+set+timezone



First link.

 



> -----Original Message-----

> From: Bryan Cantwell [mailto:bcantwell@stripped] 

> Sent: Friday, October 01, 2010 10:25 AM

> To: mysql@stripped

> Subject: Any way to change timezone WITHOUT mysqld restart?

> 

> Any way to change timezone WITHOUT mysqld restart?

> It would be a lifesaver if there were some way for me not to have to

> restart because if mysql restarts then I have to go through a lot of

> other issues with my other apps.

> 

> 

> 





Thread
Any way to change tinezone WITHOUT mysqld restart?Bryan Cantwell1 Oct
  • RE: Any way to change tinezone WITHOUT mysqld restart?Daevid Vincent2 Oct
    • RE: Any way to change timezone WITHOUT mysqld restart?Bryan Cantwell2 Oct
      • Re: Any way to change timezone WITHOUT mysqld restart?Johan De Meersman3 Oct
      • RE: Any way to change timezone WITHOUT mysqld restart?Daevid Vincent5 Oct