Home  >  Q&A  >  body text

为什么mysql的int占四个字节?

他的表示范围很大,400000多,那这样算的话一个数字就一个字节,为怎么都会说他只占4个字节呢。

PHPzPHPz2743 days ago685

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 13:28:52

    1 bit can only represent 0 or 1 (binary)
    8 bits (byte) = 1 byte
    can represent data of 2 to the power of 4*8) = 4294967296
    Because it needs There are still 0 for positive and negative, so the final representation range (decimal) is -2147483648~2147483647

    The data type of the field is fixed. For example, if you declare int(11), note: 11 here represents the length of the number
    , then no matter what the length of the stored number is (as long as it does not exceed the representation range of int(11)) mysql will
    prepare it in advance Leave so much space as int(11) to store data. The storage size will not be changed based on the size of the data

    reply
    0
  • Cancelreply