且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL - 整数列的大小限制

更新时间:2023-12-01 14:30:04

不,这是对MySQL的常见误解。实际上,长度对整数的大小或它可以存储的值的范围没有影响。

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 总是8位,可以存储2个 8 不同的值。

  • SMALLINT 总是16位,可以存储2个 16 不同的值。

  • INT 是总是32位,可以存储2个 32 不同的值。

  • BIGINT 总是64位并且可以存储2 64 不同的值。

  • 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.

还有一个MEDIUMINT,但是工作在MySQL上的工程师告诉我MEDIUMINT总是在内部被提升为32位INT,因此使用MEDIUMINT实际上没有任何好处。

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.

长度用于显示,并且这只有在你使用 ZEROFILL 选项时才有意义。

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

请参阅我对在INT(10)和INT(12)之间有什么区别(当应用于我的代码时)?