mysql 中的 INT(5) 是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8892341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does INT(5) in mysql mean?
提问by Yash Desai
I always thought INT(5) means a number which has a max size of 5 digits. I tried entering a huge number inside it and it somehow got cut down to 2147483647
我一直认为 INT(5) 表示一个最大大小为 5 位的数字。我试着在里面输入一个巨大的数字,但不知何故它被削减到 2147483647
This obviously isnt 5 digits. So what does INT(5) have a limitation of ?
这显然不是5位数。那么 INT(5) 有什么限制?
回答by ypercube??
From MySQL Docs, Numeric Type Attributes
MySQL supports an extension for optionally specifying the display width of integer data types in parentheses following the base keyword for the type. For example, INT(4)specifies an INT with a display width of four digits. This optional display width may be used by applications to displayinteger valueshaving a width less than the width specified for the column by left-padding them with spaces.(That is, this width is present in the metadata returned with result sets. Whether it is used or not is up to the application.)
MySQL 支持一个扩展,用于在类型的 base 关键字后面的括号中选择性地指定整数数据类型的显示宽度。例如,INT(4)指定显示宽度为四位的 INT 。应用程序可以使用此可选的显示宽度来显示宽度小于为列指定的宽度的整数值,方法是用空格向左填充它们。(也就是说,这个宽度存在于结果集返回的元数据中。是否使用它取决于应用程序。)
回答by NPE
INT
is always four bytes wide. The 5
is the "display width".
INT
总是四个字节宽。这5
是“显示宽度”。
回答by Umesh Moghariya
In MySQL, INT(5) does not mean that values are limited to 5-character values. It only means that MySQL will try to pad these values with spaces/zeroes when returning them.
在 MySQL 中,INT(5) 并不意味着值仅限于 5 个字符的值。这仅意味着 MySQL 在返回它们时会尝试用空格/零填充这些值。
The numeric range of any signed INT including INT(10), INT(5) or any other INT(n) is: -2,147,483,648 ... 2,147,483,647, which is 10 digits at most.
包括 INT(10)、INT(5) 或任何其他 INT(n) 在内的任何有符号 INT 的数字范围是:-2,147,483,648 ... 2,147,483,647,最多 10 位。
回答by LeleDumbo
http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html
http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html
"M indicates the maximum display width for integer types. The maximum legal display width is 255. Display width is unrelated to the range of values a type can contain, as described in Section 10.2, “Numeric Types”"
“M 表示整数类型的最大显示宽度。最大合法显示宽度是 255。显示宽度与类型可以包含的值的范围无关,如第 10.2 节,“数字类型”中所述”
回答by dukang214
https://alexander.kirk.at/2007/08/24/what-does-size-in-intsize-of-mysql-mean/
M indicates the maximum display width for integer types. For floating-point and fixed-point types, M is the total number of digits that can be stored. For string types, M is the maximum length. The maximum allowable value of M depends on the data type.
https://alexander.kirk.at/2007/08/24/what-does-size-in-intsize-of-mysql-mean/
M 表示整数类型的最大显示宽度。对于浮点和定点类型,M 是可以存储的总位数。对于字符串类型,M 是最大长度。M 的最大允许值取决于数据类型。
回答by Nirre
An int can be between -2147483648 and 2147483647 signed, or 0 and 4294967295 unsigned.
int 可以介于 -2147483648 和 2147483647 之间(有符号),或 0 和 4294967295 之间(无符号)。
Thats why it was cut down to that if you entered a number larger than it as a signed value
这就是为什么如果您输入一个大于它的数字作为有符号值,它会被缩减为
回答by Germán Ariza
A very common misconception about what int(N) means in MySQL is that the column can store maximum integer value with N digits in length. However, this is not true. int(N) does not determines the maximum value that the column can store in it. N is the display width of the integer column, unlike the characters columns where the number means number of character that can be stored.
关于 int(N) 在 MySQL 中的含义的一个非常常见的误解是该列可以存储长度为 N 位的最大整数值。然而,事实并非如此。int(N) 不确定列可以存储在其中的最大值。N 是整数列的显示宽度,与字符列不同,其中数字表示可以存储的字符数。
The number in the parenthesis does not determines the max and min values that can be stored in the integer field. The max and min values that can be stored are always fixed. The following table shows the required storage and range for each integer type.
括号中的数字不决定可以存储在整数字段中的最大值和最小值。可以存储的最大值和最小值始终是固定的。下表显示了每种整数类型所需的存储和范围。