假设你使用的是5.5,如果你看到http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html,它说:
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 NOW() or CURTIME(), and values stored in and retrieved from TIMESTAMP columns. Values for TIMESTAMP columns are converted from the current time zone to UTC for storage, and from UTC to the current time zone for retrieval.
The current time zone setting does not affect values displayed by functions such as UTC_TIMESTAMP() or values in DATE, TIME, or DATETIME columns. Nor are values in those data types stored in UTC; the time zone applies for them only when converting from TIMESTAMP values. If you want locale-specific arithmetic for DATE, TIME, or DATETIME values, convert them to UTC, perform the arithmetic, and then convert back.
所以尝试没有SESSION
,看看它的工作原理,并检查select @@session.time_zone;
给你正确的时区。
编辑:你可能只是有你的数据库的问题。我只是在我的一个数据库(5.5.8)上试过这个,它工作,但在5.0.51上失败。所以你可能需要数据库升级。
mysql> select CURRENT_TIMESTAMP();
+---------------------+
| CURRENT_TIMESTAMP() |
+---------------------+
| 2011-05-29 14:33:06 |
+---------------------+
1 row in set (0.00 sec)
mysql> set time_zone = 'Europe/Rome';
Query OK, 0 rows affected (0.00 sec)
mysql> select CURRENT_TIMESTAMP();
+---------------------+
| CURRENT_TIMESTAMP() |
+---------------------+
| 2011-05-29 16:33:11 |
+---------------------+
1 row in set (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.5.8-log |
+-----------+
1 row in set (0.00 sec)
如果您指定时间偏移量为'+01:00',该怎么办? 。 – zerkms 2011-05-29 12:25:54
@zerkms谢谢回答,但它不工作:( – 2011-05-29 13:51:53