我应该在 MySQL 中使用大 INT 还是常规 INT 来存储时间戳?
我应该在 MySQL 中使用大整数还是常规整数来存储时间戳?我计划将其存储在 INT 中,而不是内置时间戳或日期时间中,那么我应该使用哪种 INT 类型?
Should I be using a big integer or a regular integer in MySQL to store a timerstamp in? I plan on storing it in an INT and not the built in timestamp or datetime so which INT type should I use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Int 将在 2038 年变为负值(如果您使用 UNIX 时间戳): http://en.wikipedia .org/wiki/2038_problem。
所以 BIGINT 可能是最安全的选择
Int would roll over to a negative in 2038 (if you are using UNIX timestamp): http://en.wikipedia.org/wiki/2038_problem.
so BIGINT is probably the safest choice
您应该将其存储在时间戳中,因为这很可能是 DBMS 针对时间戳数据进行优化的内容。
我很好奇为什么你会牺牲 MySQL 开发人员为使时间戳按其应有的方式工作而付出的所有辛勤工作,并用几乎肯定无法正常工作的东西来替换它。
由于您没有说明为什么要使用整数,我只是假设这是暂时的精神错乱,您很快就会恢复:-)
You should be storing it in a timestamp since that's most likely what the DBMS will optimize for timestamp data.
I'm curious as to why you would sacrifice all the hard work that the MySQL developers have put into making timestamps work the way they should, and replacing it with something that will almost certainly not work as well.
Since you don't state why you want to use an integer, I'm just going to assume it was temporary insanity and that you'll soon recover :-)
我认为这完全取决于你想做什么。有一些适合时间/日期类型的类型(请参阅:http://dev.mysql.com/doc/refman/5.0/en/date-and-time-type-overview.html)
DATE
- 通常为 3 个字节,范围:1000-01-01
到9999-12-31
。DATETIME
- 8 个字节,范围1000-01-01 00:00:00
到9999-12-31 23:59:59
TIMESTAMP
- 4 字节范围1970-01-01 00:00:01
UTC 到2038-01-19 03:14:07
UTC。然后,有一些语义问题需要注意:
(int 是 4 个字节,如 TIMESTAMP,bigint 是 8 个字节,如 DATETIME)
I think it entirely depends on what you want to do. There a few proper types for time/date types (see: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-type-overview.html)
DATE
- typically 3 bytes, range:1000-01-01
to9999-12-31
.DATETIME
- 8 bytes, range1000-01-01 00:00:00
to9999-12-31 23:59:59
TIMESTAMP
- 4 bytes range1970-01-01 00:00:01
UTC to2038-01-19 03:14:07
UTC.Then, there are some semantic issues to be aware of:
(int is 4 bytes like TIMESTAMP, bigint is 8 bytes like DATETIME)