MySQL:bigint 与 int
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4769416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL: bigint Vs int
提问by laukok
I have been using int(10) and just noticed that Wordpress uses bigint(20) - What is different to use bigint(20) and int(10) for id auto increment? Which one should I use for id column?
我一直在使用 int(10) 并且刚刚注意到 Wordpress 使用 bigint(20) - 使用 bigint(20) 和 int(10) 进行 id 自动递增有什么不同?我应该为 id 列使用哪一个?
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
Vs
对比
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
Thanks.
谢谢。
回答by John Parker
The difference is purely in the maximum value which can be stored (18,446,744,073,709,551,615 for the bigint(20) and 4,294,967,295 for the int(10), I believe), as per the details on the MySQL Numeric Typesmanual page.
根据 MySQL数字类型手册页上的详细信息,区别仅在于可以存储的最大值(我相信 bigint(20) 为 18,446,744,073,709,551,615,int(10) 为 4,294,967,295)。
Incidentally, the use of (20) and (10) is largely irrelevant unless you're using ZEROFILL. (i.e.: It doesn't actually change the size of the number stored - that's all down to the type.)
顺便说一句,除非您使用 ZEROFILL,否则 (20) 和 (10) 的使用在很大程度上是无关紧要的。(即:它实际上并没有改变存储数字的大小——这完全取决于类型。)
However, in practical terms it should be noted that you're not likely to hit either of these limits any time soon, unless you're a reallyactive blogger.
但是,实际上应该注意的是,除非您是一个非常活跃的博主,否则您不太可能很快就会达到这些限制中的任何一个。
回答by Crozin
The only difference is the range of the type. INT
is a 32-bit long while BIGINT
is 64-bit long, therefore it can store much larger numbers like 123456789123456789
(which cannot be stored as INT
).
唯一的区别是类型的范围。INT
是 32 位长而BIGINT
64 位长,因此它可以存储更大的数字,例如123456789123456789
(不能存储为INT
)。
Here's a full list of MySQL integer types: http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
这是 MySQL 整数类型的完整列表:http: //dev.mysql.com/doc/refman/5.0/en/numeric-types.html