Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update timezone docs #19204

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Update timezone docs #19204

wants to merge 6 commits into from

Conversation

qiancai
Copy link
Collaborator

@qiancai qiancai commented Dec 4, 2024

What is changed, added or deleted? (Required)

Which TiDB version(s) do your changes apply to? (Required)

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions.

  • master (the latest development version)
  • v8.2 (TiDB 8.2 versions)
  • v8.1 (TiDB 8.1 versions)
  • v8.0 (TiDB 8.0 versions)
  • v7.6 (TiDB 7.6 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)
  • v6.1 (TiDB 6.1 versions)
  • v5.4 (TiDB 5.4 versions)
  • v5.3 (TiDB 5.3 versions)
  • v5.2 (TiDB 5.2 versions)
  • v5.1 (TiDB 5.1 versions)

What is the related PR or file link(s)?

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

@qiancai qiancai added needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. translation/from-docs This PR is translated from a PR in pingcap/docs. labels Dec 4, 2024
@ti-chi-bot ti-chi-bot bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Dec 4, 2024
Copy link

ti-chi-bot bot commented Dec 4, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from qiancai, ensuring that each of them provides their approval before proceeding. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 4, 2024
@hfxsd hfxsd self-requested a review December 4, 2024 09:26
Comment on lines +11 to +13
- TiDB 优先使用 `TZ` 环境变量
- 如果 `TZ` 环境变量不可用,TiDB 会从 `/etc/localtime` 的软链接中读取时区信息
- 如果上述方法均失败,TiDB 将使用 `UTC` 作为系统时区。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- TiDB 优先使用 `TZ` 环境变量。
- 如果 `TZ` 环境变量不可用,TiDB 会从 `/etc/localtime` 的软链接中读取时区信息。
- 如果上述方法均失败,TiDB 将使用 `UTC` 作为系统时区。
1. TiDB 优先使用 `TZ` 环境变量。
2. 如果 `TZ` 环境变量不可用,TiDB 会从 `/etc/localtime` 的软链接中读取时区信息。
3. 如果上述方法均失败,TiDB 将使用 `UTC` 作为系统时区。

- 数据迁移时,需要特别注意主库和从库的时区设置是否一致。
- 为了获取准确的时间戳,强烈建议使用网络时间协议(NTP)或精确时间协议(PTP)服务配置可靠的时钟。有关如何检查 NTP 服务的信息,请参考[检测及安装 NTP 服务](/check-before-deployment.md#检测及安装-ntp-服务)。
- 当使用遵循夏令时 (Daylight Saving Time, DST) 的时区时,请注意可能出现时间戳不明确或不存在的情况,特别是在对这些时间戳进行计算时。
- MySQL 需要使用 `mysql_tzinfo_to_sql` 将操作系统的时区数据库转换为 `mysql` 数据库中的表。TiDB 则可以利用 Go 编程语言的内置时区处理能力,直接从操作系统的时区数据库中读取时区数据文件。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- MySQL 需要使用 `mysql_tzinfo_to_sql` 将操作系统的时区数据库转换为 `mysql` 数据库中的表。TiDB 则可以利用 Go 编程语言的内置时区处理能力,直接从操作系统的时区数据库中读取时区数据文件。
- MySQL 需要使用 [`mysql_tzinfo_to_sql`](https://dev.mysql.com/doc/refman/8.4/en/mysql-tzinfo-to-sql.html) 将操作系统的时区数据库转换为 `mysql` 数据库中的表。TiDB 则可以利用 Go 编程语言的内置时区处理能力,直接从操作系统的时区数据库中读取时区数据文件。

{{< copyable "sql" >}}
对于时区敏感的时间值,例如由 [`NOW()`](/functions-and-operators/date-and-time-functions.md) 和 `CURTIME()` 函数返回的值,它们的显示和处理会受到当前会话时区设置的影响。如需进行时区转换,可以使用 `CONVERT_TZ()` 函数。若要获取基于 UTC 的时间戳以避免时区相关问题,可以使用 `UTC_TIMESTAMP()` 函数。

在 TiDB 中,`TIMESTAMP` 数据类型会记录时间戳的具体数值和时区信息,因此它的显示值会受到时区设置的影响。其他数据类型(如 `DATETIME`、`DATE` 和 `TIME`) 不记录时区信息,因此它们的值不会受到时区变化的影响。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
在 TiDB 中,`TIMESTAMP` 数据类型会记录时间戳的具体数值和时区信息,因此它的显示值会受到时区设置的影响。其他数据类型(如 `DATETIME``DATE``TIME` 不记录时区信息,因此它们的值不会受到时区变化的影响。
在 TiDB 中,`TIMESTAMP` 数据类型会记录时间戳的具体数值和时区信息,因此它的显示值会受到时区设置的影响。其他数据类型(如 `DATETIME``DATE``TIME`)不记录时区信息,因此它们的值不会受到时区变化的影响。


- 在 `TIMESTAMP` 和 `DATETIME` 值的转换过程中,会涉及到时区。这种情况一律基于当前会话的 `time_zone` 时区处理。
- 数据迁移时,需要特别注意主库和从库的时区设置是否一致。
- 为了获取准确的时间戳,强烈建议使用网络时间协议(NTP)或精确时间协议(PTP)服务配置可靠的时钟。有关如何检查 NTP 服务的信息,请参考[检测及安装 NTP 服务](/check-before-deployment.md#检测及安装-ntp-服务)。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 为了获取准确的时间戳,强烈建议使用网络时间协议NTP或精确时间协议PTP服务配置可靠的时钟。有关如何检查 NTP 服务的信息,请参考[检测及安装 NTP 服务](/check-before-deployment.md#检测及安装-ntp-服务)
- 为了获取准确的时间戳,强烈建议使用网络时间协议 (NTP) 或精确时间协议 (PTP) 服务配置可靠的时钟。有关如何检查 NTP 服务的信息,请参考[检测及安装 NTP 服务](/check-before-deployment.md#检测及安装-ntp-服务)

@@ -6,51 +6,61 @@ summary: TiDB 使用的时区由全局变量和 session 变量决定。全局变

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

英文的 summary 不如中文详细,可以和中文保持一致。

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Dec 4, 2024
Copy link

ti-chi-bot bot commented Dec 4, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-12-04 15:04:15.515792701 +0000 UTC m=+1253643.135447218: ☑️ agreed by hfxsd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-1-more-lgtm Indicates a PR needs 1 more LGTM. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. translation/from-docs This PR is translated from a PR in pingcap/docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants