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

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


当前回答

根据这里,int(11)将占用4个字节的空间,即2^(31)= 2147483648 max值和-2147483648min值的32位空间。一位是符号。

其他回答

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

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

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

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

根据这本书:

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

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手册

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