如何使 MySQL 的 NOW() 和 CURDATE() 函数使用 UTC?

2022-01-16 00:00:00 timezone utc mysql

我想让它在 MySQL 查询中调用 NOW() 和 CURDATE() 以 UTC 格式返回日期.如何在不经历和更改所有使用这些函数的查询的情况下实现这一点?

I want to make it so calls to NOW() and CURDATE() in MySQL queries return the date in UTC. How do I make this happen without going through and changing all queries that use these functions?

推荐答案

终于找到我要找的了...

Finally found what I was looking for...

在 my.cnf 中,

In my.cnf,

[mysqld_safe]
timezone = UTC

我把这个选项放在 [mysqld] 下,mysql 无法启动.

I was putting this option under [mysqld], and mysql was failing to start.

调用SET time_zone='+0:00';"在每个页面加载时也可以工作,但我不喜欢在每个页面加载时调用该查询的想法.

Calling "SET time_zone='+0:00';" on every page load would also work, but I don't like the idea of calling that query on every single page load.

相关文章