原文: 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:

  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 .

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

Mysql的BigInt(20),Int(20)以及Bigint(32)有区别吗?的更多相关文章

  1. mysql中bigint、int、mediumint、smallint 和 tinyint的取值范围

    mysql数据库设计,其中,对于数据性能优化,字段类型考虑很重要,搜集了些资料,整理分享出来,这篇为有关mysql整型bigint.int.mediumint.smallint 和 tinyint的语 ...

  2. MySQL整数类型说明 int(11) vs int(20)

    整数类型后面跟的是显示的宽度.M指示最大显示宽度.最大有效显示宽度是255.显示宽度与存储大小或类型包含的值的范围无关. 实践出真知: mysql> create table test2 ( a ...

  3. mysql中bigint、int、mediumint、smallint与tinyint的取值范围

    https://blog.csdn.net/github_39110707/article/details/74277381 mysql数据库设计,其中对性能优化,字段类型很重要,下面对bigint. ...

  4. MYSQL性能优化的最佳20+条经验

    MYSQL性能优化的最佳20+条经验 2009年11月27日 陈皓 评论 148 条评论  131,702 人阅读 今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数 ...

  5. Column count of mysql.proc is wrong. Expected 20, found 16. Created with MySQL 50096, now running 50173.

    IDEA链接mysql提示 Column count of mysql.proc is wrong. Expected 20, found 16. Created with MySQL 50096, ...

  6. 如何将生产环境的字段类型从INT修改为BIGINT

    介绍 改变数据类型是一个看起来很简单的事情,但是如果表非常大或者有最小停机时间的要求,又该如何处理那?这里我提供一个思路来解决这个问题. 背景 在一个常规SQL Server heath检查中,使用s ...

  7. tinyint、smallint、bigint、int 区别

    1byte=8bit   [tinyint] 从 0 到 255 的整型数据.存储大小为 1 字节.如果设置为UNSIGNED类型,只能存储从0到255的整数,不能用来储存负数. [smallint] ...

  8. column count of mysql.proc is wrong. expected 20,found 16. the table is probably corruptd.

    1558 1547 column count of mysql.proc is wrong. expected 20,found 16. the table is probably corruptd. ...

  9. SQLServer bigint 转 int带符号转换函数(原创)

    有一个需求是要在一个云监控的状态值中存储多个状态(包括可同时存在的各种异常.警告状态)使用了位运算机制在一个int型中存储. 现在监控日志数据量非常大(亿级别)需要对数据按每小时.每天进行聚合,供在线 ...

随机推荐

  1. Linux正则表达式与通配符

    在linux中,有通配符和正则表达式,这是两个不同的概念通配符:它是由shell解析,并且一般用于匹配文件名.如:ls正则表达式:是一个字符匹配标准,可以匹配文本中的内容一些命令工具按此标准实现字符匹 ...

  2. 开源项目(5-2) yolo打包成库

    Windows系统下YOLO动态链接库的封装和调用 Windows10+VS2015+OpenCV3.4.1+CUDA8.0+cuDNN8.0 参考教程 https://blog.csdn.net/s ...

  3. 05_配置交换机SSH服务(数通华为)

    1. 网络拓扑: 2. SW1配置:2.1 配置为Access口,vlan 10:[SW1]vlan 10[SW1-GigabitEthernet0/0/1]port link-type access ...

  4. nave node 的虚拟环境管理工具

    nave 是类似python venv 的node 虚拟环境管理工具 安装 npm install -g nave 简单使用 帮助命令 Usage: nave <cmd> Commands ...

  5. 从Hello World 来讲解线程

    从一个经典的例子开始:一个打印“Hello World.”的程序.一个非常简单的在单线程中运行的Hello World程序如下所示,当我们谈到多线程时,它可以作为一个基准. #include<i ...

  6. Docker原理及使用

    虚拟化系统: 1. Type-I: 此种虚拟化是Hypervisor直接运行在硬件之上,来创建虚拟机. 2. Type-II: 这种虚拟化类似与VMware Workstations. IPC: 在相 ...

  7. Vue与REACT两个框架的区别和优势对比

    VUE和REACT两个JavaScript框架都是当下比较受欢迎的,他们两者之间的区别有那些,各自的优缺点是什么,本文将为你呈现. 简单介绍 除非你最近一直不关注前端的发展,不然你肯定听说过由Face ...

  8. 5098: [BZOJ1098][POI2007]办公楼biu

    5098: [BZOJ1098][POI2007]办公楼biu 没有数据结构就很棒 一个看上去非常玄学的代码 const int N=1e5+10,M=2e6+10; int n,m; int fa[ ...

  9. Gradle系列教程之依赖管理

    这一章我将介绍Gradle对依赖管理的强大支持,学习依赖分组和定位不同类型仓库.依赖管理看起来很容易,但是当出现依赖解析冲突时就会很棘手,复杂的依赖关系可能导致构建中依赖一个库的多个版本.Gradle ...

  10. E4A碰到打开自动闪退又自动打开又闪退一直循环的问题

    E4A碰到打开自动闪退又自动打开又闪退一直循环的问题 这几天写了一个脚本,自己手机上,模拟器上,均测试没有问题,可以正常操作 发给另一个人,他那边居然没有一个设备能运行成功! 而且一直闪退,闪退后又打 ...