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

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


当前回答

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(11)将占用4个字节的空间,即2^(31)= 2147483648 max值和-2147483648min值的32位空间。一位是符号。

不管指定的长度是多少,INT总是4个字节。

TINYINT = 1字节(8位) SMALLINT = 2字节(16位) MEDIUMINT = 3字节(24位) INT = 4字节(32位) BIGINT = 8字节(64位)。

长度只是指定在使用mysql命令行客户端选择数据时要填充多少字符。12345存储为int(3)将仍然显示为12345,但如果它存储为int(10),它仍然显示为12345,但您可以选择填充前五位数字。例如,如果您添加了ZEROFILL,它将显示为0000012345。

... 最大值将是2147483647(有符号)或4294967295(无符号)

根据这本书:

MySQL允许您为整数类型指定一个“宽度”,例如INT(11)。 对于大多数应用程序来说,这是没有意义的:它没有限制 合法的值范围,但只是指定字符的数量 MySQL的交互工具将保留用于显示目的。为 为了存储和计算目的,INT(1)与INT(20)是相同的。

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

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

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

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