Mysql的BigInt(20),Int(20)以及Bigint(32)有区别吗?

Wesley13
• 阅读 751

原文: http://stackoverflow.com/questions/3135804/types-in-mysql-bigint20-vs-int20-etcc

http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html

Types in MySQL: BigInt(20) vs Int(20) etcc

See http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html

INT is a four-byte signed integer. BIGINT is an eight-byte signed integer.

The 20 in INT(20) and BIGINT(20) means almost nothing. It's a hint for display width, it has nothing to do with storage. Practically, it affects only the ZEROFILL option:

Sql代码   Mysql的BigInt(20),Int(20)以及Bigint(32)有区别吗?

  1. CREATE TABLE foo ( bar INT(20) ZEROFILL );

  2. INSERT INTO foo (bar) VALUES (1234);

  3. SELECT bar from foo;

  4. +----------------------+

  5. | bar                  |  

  6. +----------------------+

  7. | 00000000000000001234 |  

  8. +----------------------+

 

The number in parentheses in a type declaration is display width , which is unrelated to the range of values that can be stored in a data type. Just because you can declare Int(20) does not mean you can store values up to 10^20 in it:

[...] 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. ...

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.

For a list of the maximum and minimum values that can be stored in each MySQL datatype, see here .

Mysql的BigInt(20),Int(20)以及Bigint(32)有区别吗?

一个INT,占4个字节,跟JAVA中的int一样,即使是有符号也能表达21亿 这么大的数据。 所以平时绝大多数情况,包括大型网站的UID,都用不了这么大的数据,好友关系表可能会超过,关系表可以考虑用BIGINT。还有就是平时时间戳需要用BIGINT。总之,不要轻易用上BIGINT,完全是浪费!

点赞
收藏
评论区
推荐文章
Wesley13 Wesley13
2年前
VirturalBox中搭建CentOS开发环境实录(二)
安装MySQL_Yum__安装:_官方安装步骤:http://dev.mysql.com/doc/refman/5.7/en/linuxinstallationyumrepo.html(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fdev.
Wesley13 Wesley13
2年前
mysql使用utf8mb4经验吐血总结
mysql使用utf8mb4经验吐血总结1\.utf8与utf8mb4异同先看官方手册https://dev.mysql.com/doc/refman/5.6/en/charsetunicodeutf8mb4.html(https://www.o
Stella981 Stella981
2年前
HIVE 时间操作函数
日期函数UNIX时间戳转日期函数: from\_unixtime语法:   from\_unixtime(bigint unixtime\, string format\)返回值: string说明: 转化UNIX时间戳(从19700101 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式举例:hive   selec
Stella981 Stella981
2年前
MyBatis(四):mybatis中使用in查询时的注意事项
准备工作1)创建测试表jobitemCREATETABLE"jobitem"("id"bigint(20)NOTNULLAUTO_INCREMENTCOMMENT'唯一键pk',"appId"varchar(32)NOTNULLCOMMENT'yarn任务id(appl
Wesley13 Wesley13
2年前
MySQL 锁(5)
InnoDB引擎有8类锁https://dev.mysql.com/doc/refman/5.7/en/innodblocking.html(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.7%2Fen%2
Wesley13 Wesley13
2年前
Mysql 分区表
DROPTABLEIFEXISTS\frank\_test\;CREATETABLE\frank\_test\(\id\bigint(20)NOTNULLAUTO\_INCREMENTCOMMENT'主键id',\gid\bigint(20)DEFAULT'0'COMMENT'基础表id'
Wesley13 Wesley13
2年前
mysql中int、bigint、smallint 和 tinyint的区别与长度
通过创建一张表,来看看mysql中intbigintsmallint和tinyint的区别与长度1、在mysql命令行创建如下表CREATETABLEtest_int_1(int_idintNOTNULL,bigint_idbigintDEFAULTNULL,
Wesley13 Wesley13
2年前
Mysql中判断一个点是否落在多边形内
关于地理空间数据,经常需要处理两个空间数据的关联关系。有很多种方法可以处理,通过编写程序算法,或者是调用数据库中对应的function。在mysql数据库中,https://dev.mysql.com/doc/refman/5.1/en/functionsfortestingspatialrelationsbetweengeometricobj
Wesley13 Wesley13
2年前
MySQL学习(三)
MySQL函数官网:https://dev.mysql.com/doc/refman/5.7/en/funcopsummaryref.html(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.7%
Wesley13 Wesley13
2年前
mysql 5.7.x 的密码
mysql5.7.x的密码设置、重设、忘记密码:(参考:http://dev.mysql.com/doc/refman/5.7/en/resettingpermissions.html)(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fdev.mysql.com%2Fdoc%2Fre