Jump to content

Archived

This topic is now archived and is closed to further replies.

johnnyk

Set timezone

Recommended Posts

I've asked this question before but have never gotten an answer:

So I want to set the timezone for MySQL. mysql.org says I should use this:
mysql> SET GLOBAL time_zone = timezone;

But what do I do with that? I tried inserting it into .htaccess and I tried using mysql_query(SET GLOBAL time_zone = timezone;) in PHP, but neither worked. What do I do?

Share this post


Link to post
Share on other sites
In the shell, if you use Linux, you could do something like this: [code]daniel@daniel:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 36 to server version: 5.0.22-Debian_0ubuntu6.06-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> SET GLOBAL time_zone = '+1:00';[/code]

Or in PHP you could do it in this way: [code]<?php
$link = mysql_connect("localhost","root","password");
mysql_query("SET GLOBAL time_zone = '+1:00';");
?>[/code]

These examples will set the timezone to GMT+1 (CET).

Share this post


Link to post
Share on other sites
It's not working. No errors or anything, but it doesn't change the timezone.

Also, what does it mean to set it to GLOBAL? What would it do differently?

Share this post


Link to post
Share on other sites
Assuming you're logged in as MySQL root, there should be no reason why the timezone isn't changing, unless your my.cnf file says otherwise.  GLOBAL is as opposed to SESSION, which only affects the current connection.

Share this post


Link to post
Share on other sites
2 questions:
-How do I view the my.cnf file (I'm using a hosting company, mysql isn't on my computer)
-So if I use GLOBAL, do I only need to do it once ever, and never include it with any page with queries?

Share this post


Link to post
Share on other sites
Most likely your hosting company won't let you edit it... you'd have to check with them.  GLOBAL is global for the server, but won't survive a restart, AFAIK.

Share this post


Link to post
Share on other sites
I don't understand what GLOBAL does then? Does it keep the timezone for the session or something?

Share this post


Link to post
Share on other sites
GLOBAL is across sessions, SESSION is per session.

Share this post


Link to post
Share on other sites
[quote]GLOBAL is global for the server, but won't survive a restart, AFAIK.[/quote]
Do you mean a server restart?

Share this post


Link to post
Share on other sites
Correct.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.