BIGINT(8) 是 mysql 可以存储的最大整数吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1632312/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:22:12  来源:igfitidea点击:

Is BIGINT(8) the largest integer mysql can store?

sqlmysql

提问by Citizen

I've got some numbers that is now larger than INT can handle.

我有一些现在大于 INT 可以处理的数字。

This is a bit embarassing, but I honestly don't know exactly what the BIGINT(8) means. Is the 8 in that the max bit value or the max length?

这有点尴尬,但老实说,我不知道 BIGINT(8) 到底是什么意思。8 是最大位值还是最大长度?

So BIGINT(1) can only be one digit? Or is BIGINT(1) something else? I think tinyint(1) max is 127, how does that work out?

所以 BIGINT(1) 只能是一位数?或者 BIGINT(1) 是别的什么东西?我认为 tinyint(1) max 是 127,它是如何工作的?

What is the biggest I can make BIGINT? What is the largest number I can store in mysql as an integer?

我可以制作的最大 BIGINT 是多少?我可以在 mysql 中作为整数存储的最大数字是多少?

采纳答案by Greg

The number represents how it's displayed - it doesn't affect how the data is stored.

数字代表它的显示方式——它不影响数据的存储方式。

From the manual:

手册

Another extension is supported by MySQL for optionally specifying the display width of integer data types in parentheses following the base keyword for the type (for example, INT(4)). This optional display width may be used by applications to display integer values having 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.)

The display width does not constrain the range of values that can be stored in the column, nor the number of digits that are displayed for values having a width exceeding that specified for the column. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range allowed by three characters are displayed using more than three characters.

MySQL 支持另一个扩展,用于在类型的基本关键字之后的括号中选择性地指定整数数据类型的显示宽度(例如,INT(4))。应用程序可以使用此可选的显示宽度来显示宽度小于为列指定的宽度的整数值,方法是用空格向左填充它们。(也就是说,这个宽度存在于结果集返回的元数据中。是否使用它取决于应用程序。)

显示宽度不限制可以存储在列中的值的范围,也不限制宽度超过列指定值的值显示的位数。例如,指定为 SMALLINT(3) 的列通常具有 -32768 到 32767 的 SMALLINT 范围,并且使用三个以上的字符显示超出三个字符允许范围的值。

A BIGINT is always 8 bytes and can store -9223372036854775808 to 9223372036854775807 (signed) or 0 to 18446744073709551615 (unsigned).

BIGINT 总是 8 个字节,可以存储 -9223372036854775808 到 9223372036854775807(有符号)或 0 到 18446744073709551615(无符号)。

回答by Abel

You answer is in this overview. A BIGINT is indeed 8 bytes. A TinyInt only 1.

您的答案在此概述中。BIGINT 确实是 8 个字节。一个 TinyInt 只有 1。

Btw, I don't consider the range from -9223372036854775808to 9223372036854775807very embarrassing, it's +/-2^63 :).

顺便说一句,我不考虑从-92233720368547758089223372036854775807非常尴尬的范围,它是 +/-2^63 :)。

回答by Andre Miller

The number between brackets is the 'display width' and is unrelated the range of numbers the datatype can actually store.

括号之间的数字是“显示宽度”,与数据类型实际可以存储的数字范围无关。

A BIGINT's range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615.

BIGINT 的范围是 -9223372036854775808 到 9223372036854775807。无符号范围是 0 到 18446744073709551615。

You can find more information here: http://dev.mysql.com/doc/refman/5.4/en/numeric-type-overview.html

您可以在此处找到更多信息:http: //dev.mysql.com/doc/refman/5.4/en/numeric-type-overview.html

回答by soulmerge

The number merely defines the width of the number when being displayed. Have a look at the mysql manual for sizes of numeric types.

数字仅定义显示时数字的宽度。查看 mysql 手册了解数字类型的大小

回答by Ruud H.G. van Tol

To store a 128-bit integer, you can use a BINARY(16).

要存储 128 位整数,可以使用 BINARY(16)。

For 252:

对于 252:

SELECT RIGHT(CONCAT(REPEAT("\0",16),UNHEX(CONV(252,10,16))),16);

选择权(CONCAT(重复(“\ 0”,16),UNHEX(CONV(252,10,16))),16);

or equivalently:

或等效地:

SELECT UNHEX(RIGHT(CONCAT(REPEAT("0",32),HEX(252)),32));

SELECT UNHEX(RIGHT(CONCAT(REPEAT("0",32),HEX(252)),32));

(but MySQL integer calculations are 64-bit)

(但 MySQL 整数计算是 64 位的)

See also the recent IPv6 functions INET6_ATON() and INET6_NTOA(), http://dev.mysql.com/doc/refman/5.6/en/miscellaneous-functions.html#function_inet6-atonand how they use a VARBINARY(16).

另请参阅最近的 IPv6 函数 INET6_ATON() 和 INET6_NTOA(),http://dev.mysql.com/doc/refman/5.6/en/miscellaneous-functions.html#function_inet6-aton 以及它们如何使用 VARBINARY(16) .