在mysql中int(11)的列的大小是多少?
和可以存储在这些列中的最大值?
在mysql中int(11)的列的大小是多少?
和可以存储在这些列中的最大值?
当前回答
虽然这个答案不太可能出现,但我认为有必要进行以下澄清:
the (n) behind an integer data type in MySQL is specifying the display width the display width does NOT limit the length of the number returned from a query the display width DOES limit the number of zeroes filled for a zero filled column so the total number matches the display width (so long as the actual number does not exceed the display width, in which case the number is shown as is) the display width is also meant as a useful tool for developers to know what length the value should be padded to
A BIT OF DETAIL the display width is, apparently, intended to provide some metadata about how many zeros to display in a zero filled number. It does NOT actually limit the length of a number returned from a query if that number goes above the display width specified. To know what length/width is actually allowed for an integer data type in MySQL see the list & link: (types: TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT); So having said the above, you can expect the display width to have no affect on the results from a standard query, unless the columns are specified as ZEROFILL columns OR in the case the data is being pulled into an application & that application is collecting the display width to use for some other sort of padding.
主要参考资料:https://blogs.oracle.com/jsmyth/entry/what_does_the_11_mean
其他回答
根据这里,int(11)将占用4个字节的空间,即2^(31)= 2147483648 max值和-2147483648min值的32位空间。一位是符号。
在mysql中int(11)的列的大小是多少?
(11) - int数据类型的这个属性与列的大小无关。它只是整数数据类型的显示宽度。从11.1.4.5。属性:
MySQL支持可选地指定显示的扩展 base关键字后面括号中的整数数据类型的宽度 对于类型。例如,INT(4)指定带显示的INT 四位数字的宽度。
正如其他人所说,列可以存储的最小/最大值以及以字节为单位占用多少存储空间仅由类型定义,而不是长度。
很多答案都说(11)部分只影响显示宽度,这并不完全正确,但主要是这样。
int(2)不指定零填充的定义:
仍然接受100的值 输出时仍然显示值100(不是0或00) 显示宽度将是选择查询输出的最大值的宽度。
(2)将做的唯一一件事是如果还指定了zerofill:
值1将显示为01。 在显示值时,列的宽度将始终为该列可能获得的最大值(对于整数来说是10位数字),而不是显示该列在特定选择查询中需要显示的最大值所需的最小宽度(可能要小得多)。 列仍然可以接受,并显示超过长度的值,但这些值不会以0作为前缀。
了解所有细微差别的最佳方法是运行:
CREATE TABLE `mytable` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`int1` int(10) NOT NULL,
`int2` int(3) NOT NULL,
`zf1` int(10) ZEROFILL NOT NULL,
`zf2` int(3) ZEROFILL NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `mytable`
(`int1`, `int2`, `zf1`, `zf2`)
VALUES
(10000, 10000, 10000, 10000),
(100, 100, 100, 100);
select * from mytable;
它将输出:
+----+-------+-------+------------+-------+
| id | int1 | int2 | zf1 | zf2 |
+----+-------+-------+------------+-------+
| 1 | 10000 | 10000 | 0000010000 | 10000 |
| 2 | 100 | 100 | 0000000100 | 100 |
+----+-------+-------+------------+-------+
这个答案是在Linux的MySQL 5.7.12上测试的,在其他实现中可能有变化,也可能没有变化。
我认为int(11)的最大值是4294967295
4294967295是答案,因为int(11)显示最多11位数字IMO