MySQL - Size Limits to Integer Columns

前端 未结 2 1008
青春惊慌失措
青春惊慌失措 2020-12-05 10:07

I\'m using phpMyAdmin to create my table structures.

I can read from the documentation pages on MySQL about size limits for Integer Types: MySQL Integer Types Refere

2条回答
  •  無奈伤痛
    2020-12-05 10:46

    No, this is a common misconception about MySQL. In fact, the "length" has no effect on the size of an integer or the range of values it can store.

    • TINYINT is always 8 bits and can store 28 distinct values.
    • SMALLINT is always 16 bits and can store 216 distinct values.
    • INT is always 32 bits and can store 232 distinct values.
    • BIGINT is always 64 bits and can store 264 distinct values.

    There's also a MEDIUMINT, but the engineers who work on MySQL tell me MEDIUMINT always gets promoted to a 32-bit INT internally, so there's actually no benefit to using MEDIUMINT.

    The length is only for display, and this only matters if you use the ZEROFILL option.

    See an example in my answer to What is the difference (when being applied to my code) between INT(10) and INT(12)?

提交回复
热议问题