1

我想将我们的 mysql 服务器从共享主机迁移到本地服务器。

当前服务器位于 MST 时区,databsse 中 CURRENT_TIMESTAMP 的值存储为 -7:00 GMT。

现在我想在印度的专用服务器上移动完整的应用程序。还希望将存储在 -7:00 GMT 中的日期值转换为 +5:30 GMT。

我可以通过编写脚本来更新时间来完成更新日期的任务,但是我想知道是否有任何方法可以从数据库本身执行此操作(在导入时或在导出时)

mysql 版本 5.0.96-日志。我没有在 UTC 中获得选项导出时间戳。

4

2 回答 2

3

When using mysqldump, set the flag: --tz-utc to force all timestamps to be exported as UTC. ( http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_tz-utc ). Note here --tz-utc is enabled by default. So you should have to do nothing: but test first :)

If just working with timestamps on the server you don't have to do anything to convert them, from the documentation on TIMESTAMP post MySQL 4.1 ( http://dev.mysql.com/doc/refman/4.1/en/timestamp.html ):

"values still are stored in UTC, but are converted from the current time zone for storage, and converted back to the current time zone for retrieval. As long as the time zone setting remains constant, you get back the same value you store. If you store a TIMESTAMP value, and then change the time zone and retrieve the value, the retrieved value is different from the value you stored."

This is easy to test:

  1. Save a timestamp to your table
  2. Change the server's timezone
  3. Retrieve it: the return value should reflect the new timezone.

So another option is you could just have both the servers set to the same timezone while doing the export / import, than set them back to the correct timezone(s) after it is complete, but note with MySQLDump this should not be necessary.

于 2013-02-06T15:41:25.787 回答
-3

一般语法

SELECT DATE_ADD(<column_name>, INTERVAL HOUR);

用于将 UTC 更改为 MST

SELECT DATE_ADD(NOW(), INTERVAL 7 HOUR);
于 2014-02-14T22:30:45.317 回答