mysql 不同的服务器,相同的内容,不同的计数

标签 mysql

我有 2 个服务器,live 和 beta,并且在 live 和 beta 之间有 2 个相同的数据库,但是 count() 返回不同的数字

直播:

mysql> SELECT COUNT(*) FROM `tbl_application_user` WHERE created >= '2014-06-01 00:00:01' and created < '2014-07-01 23:59:59';
+----------+
| COUNT(*) |
+----------+
|     3432 |
+----------+
1 row in set (0.02 sec)

测试版(ubuntu、mysql):

mysql> SELECT COUNT(*) FROM `tbl_application_user` WHERE created >= '2014-06-01 00:00:01' and created < '2014-07-01 23:59:59';
+----------+
| COUNT(*) |
+----------+
|     3444 |
+----------+
1 row in set (0.00 sec)

当我在我的笔记本电脑(Windows 8.1,mysql)上尝试本地 mysql 时,它返回与实时相同的数字。

mysql> SELECT COUNT(*) FROM `tbl_application_user` WHERE created >= '2014-06-01
00:00:01' and created < '2014-07-01 23:59:59';
+----------+
| COUNT(*) |
+----------+
|     3432 |
+----------+
1 row in set (0.03 sec)
mysql>

是什么导致 BETA 服务器返回不同的数字?

谢谢,

最佳答案

BETA 服务器上的时区可能与其他机器上的时区不同。虽然时间和日期存储为 UTC,但当按字面意义使用时,它们将在连接的时区中解释,如查询的 WHERE 部分。

供您引用:11.3.1 The DATE, DATETIME, and TIMESTAMP Types

MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. (This does not occur for other types such as DATETIME.) By default, the current time zone for each connection is the server's time. The time zone can be set on a per-connection basis. 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 occurs because the same time zone was not used for conversion in both directions. The current time zone is available as the value of the time_zone system variable. For more information, see Section 10.6, “MySQL Server Time Zone Support”.

关于mysql 不同的服务器,相同的内容,不同的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24628393/

相关文章:

php - 向 MySQL 中插入数据,在字段中添加双引号

mysql - 数据库组的正确术语

sql - MySQL:什么是 LIKE 的反向版本?

MYSQL - 连接到右表上的最后一条记录 PREVIOUS 从左表记录

mysql - 避免将数据插入到 mysql 数据库中的新行中

php - 无论我做什么,相同的值都存储在 MySQL 表字段中

mysql - 外键返回空结果

mysql - Hibernate:删除父实体会触发子实体的更新查询

mysql - 在 MySQL 中不重复地插入

mysql - 一个 RTT 中包含多个 SQL 命令?