如果我在 MySQL 中存储 int(255),最大数字是多少?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7171312/
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
What is the MAX number if I store int(255) in MySQL?
提问by DNB5brims
I use int(255) in mysql as my id. Is this long enough? If I got about 1,000,000 records....Thank you.
我在 mysql 中使用 int(255) 作为我的 id。这够长了吗?如果我有大约 1,000,000 条记录....谢谢。
回答by Paul
Something is probably just converting that to int(11)
for you. Since you can't have 255 visible digits in an int
, the maximum value will be 2147483647
.
有些东西可能只是int(11)
为你转换成。由于 中不能有 255 个可见数字int
,因此最大值将为2147483647
。
If you need more than that you can set it to be unsigned, since I'm assuming you have no negative ids and then you can have up to 4294967295
.
如果您需要更多,您可以将其设置为未签名,因为我假设您没有负 id,那么您最多可以拥有4294967295
.
If you are ever going to have more than 4 billion records (very unlikely if you're at 1 million right now), then you could use a bigint
instead, which allows you to store numbers up to 18446744073709551615
at a cost of more storage space of course.
如果您将拥有超过 40 亿条记录(如果您现在有 100 万条记录,则不太可能),那么您可以使用 abigint
代替,它允许您以18446744073709551615
更多存储空间为代价来存储数字.
回答by gbn
回答by xdazz
The INT
in mysql
use 4 byte storage, and range from -2147483648 to 2147483647. If you use unsigned int, the range is 0 to 4294967295.
的INT
在mysql
使用4字节的存储,并从范围-2147483648到2147483647。如果使用 unsigned int,则范围为0 到 4294967295。
回答by Rockallite
See this blog.
请参阅此博客。
SELECT ~0 as max_bigint_unsigned
, ~0 >> 32 AS max_int_unsigned
, ~0 >> 40 AS max_mediumint_unsigned
, ~0 >> 48 AS max_smallint_unsigned
, ~0 >> 56 AS max_tinyint_unsigned
, ~0 >> 1 AS max_bigint_signed
, ~0 >> 33 AS max_int_signed
, ~0 >> 41 AS max_mediumint_signed
, ~0 >> 49 AS max_smallint_signed
, ~0 >> 57 AS max_tinyint_signed
\G
*************************** 1. row ***************************
max_bigint_unsigned: 18446744073709551615
max_int_unsigned: 4294967295
max_mediumint_unsigned: 16777215
max_smallint_unsigned: 65535
max_tinyint_unsigned: 255
max_bigint_signed: 9223372036854775807
max_int_signed: 2147483647
max_mediumint_signed: 8388607
max_smallint_signed: 32767
max_tinyint_signed: 127
1 row in set (0.00 sec)
回答by Deele
If unisgned, from 0 to 4 294 967 295, so that is more than eough.
如果 unisgned,从 0 到 4 294 967 295,这样就足够了。
More info in mysql docs.
mysql 文档中的更多信息。