开发者

What is the MAX number if I store int(255) in MySQL?

开发者 https://www.devze.com 2023-03-30 13:54 出处:网络
I use in开发者_开发问答t(255) in mysql as my id. Is this long enough? If I got about 1,000,000 records....Thank you. Something is probably just converting that to int(11) for you. Since you can\'t hav

I use in开发者_开发问答t(255) in mysql as my id. Is this long enough? If I got about 1,000,000 records....Thank you.


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.

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.

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.


-2147483648 to 2147483647 as per the docs for a signed 32 bit integer value

The 255 is simply display width and doesn't affect the range of values


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.


If unisgned, from 0 to 4 294 967 295, so that is more than eough.

More info in mysql docs.


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消