在mysql中int(11)的列的大小是多少?

和可以存储在这些列中的最大值?


当前回答

我认为int(11)的最大值是4294967295

其他回答

在mysql中int(11)的列的大小是多少?

(11) - int数据类型的这个属性与列的大小无关。它只是整数数据类型的显示宽度。从11.1.4.5。属性:

MySQL支持可选地指定显示的扩展 base关键字后面括号中的整数数据类型的宽度 对于类型。例如,INT(4)指定带显示的INT 四位数字的宽度。

在MySQL中,整数int(11)的大小为4字节,等于32位。

带符号的值是-2的32-1次方到0到2的32-1次方-1 = -2147483648到0到2147483647

无符号值是:0到2^32-1 = 0 ~ 4294967295

A good explanation for this can be found here To summarize : The number N in int(N) is often confused by the maximum size allowed for the column, as it does in the case of varchar(N). But this is not the case with Integer data types- the number N in the parentheses is not the maximum size for the column, but simply a parameter to tell MySQL what width to display the column at when the table's data is being viewed via the MySQL console (when you're using the ZEROFILL attribute). The number in brackets will tell MySQL how many zeros to pad incoming integers with. For example: If you're using ZEROFILL on a column that is set to INT(5) and the number 78 is inserted, MySQL will pad that value with zeros until the number satisfies the number in brackets. i.e. 78 will become 00078 and 127 will become 00127. To sum it up: The number in brackets is used for display purposes. In a way, the number in brackets is kind of usless unless you're using the ZEROFILL attribute. So the size for the int would remain same i.e., -2147483648 to 2147483648 for signed and 0 to 4294967295 for unsigned (~ 2.15 billions and 4.2 billions, which is one of the reasons why developers remain unaware of the story behind the Number N in parentheses, as it hardly affects the database unless it contains over 2 billions of rows), and in terms of bytes it would be 4 bytes.

关于整数类型大小/范围的更多信息,请参阅MySQL手册

INT(x)只会在显示方面有所不同,即以x位数显示数字,而不限于11。您使用ZEROFILL对它进行配对,它将在0的前面,直到它匹配您的长度。

对于INT(x)中的任意个数的x

如果存储值的数字小于x,则ZEROFILL将在0的前面。

INT(5)存储值为32的ZEROFILL将显示00032 存储值为32的INT(5)将显示32 INT的存储值为32将显示32

如果存储值的数字比x多,它将按原样显示。

INT(3)存储值为250000的ZEROFILL将显示250000 存储值为250000的INT(3)将显示250000 存储值为250000的INT将显示250000

存储在数据库中的实际值不受影响,大小仍然相同,任何计算都将正常进行。

这也适用于BIGINT, MEDIUMINT, SMALLINT和TINYINT。

4294967295是答案,因为int(11)显示最多11位数字IMO