原文: 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. 大文件断点续传webupload插件

    javaweb上传文件 上传文件的jsp中的部分 上传文件同样可以使用form表单向后端发请求,也可以使用 ajax向后端发请求 1. 通过form表单向后端发送请求 <form id=&quo ...

  2. 封装好的observer.js,用于非父子组件传值,直接调用$on和$emit方法

    const eventList = {} const $on = (eventName,callback)=>{ if(!eventList[eventName]){ eventList[eve ...

  3. AntDesign-React与VUE有点不一样,第一篇深入了解React的概念之一:JSX

    AntDesign-React与VUE有点不一样,第一篇深入了解React的概念之一:JSX 一.什么是JSX 使用JSX声明一个变量(REACT当中的元素): const element =< ...

  4. ~/.ssh/config文件的使用

    Host github-A HostName github.com User git IdentityFile /Users/xxx/.ssh/id_rsa_A IdentitiesOnly yes ...

  5. 5G 融合计费系统架构设计与实现(一)

    5G 融合计费系统架构设计与实现(一) 随着5G商用临近,5G的各个子系统也在加紧研发调试,本人有兴全程参与5G中的融合计费系统(CCS)的设计.开发.联调工作.接下来将用几篇文章介绍我们在CCS实现 ...

  6. 第08组 Alpha冲刺(4/4)

    小李的博客 作业博客 作业链接 组员1李昕晖(组长) 过去两天完成了哪些任务 文字/口头描述 11月20日了解各个小组的进度与难以攻破的地方,晚上安排开会,安排新的冲刺任务. 实现地图功能 展示Git ...

  7. Leetcode 222:完全二叉树的节点个数

    题目 给出一个完全二叉树,求出该树的节点个数. 说明: 完全二叉树的定义如下:在完全二叉树中,除了最底层节点可能没填满外,其余每层节点数都达到最大值,并且最下面一层的节点都集中在该层最左边的若干位置. ...

  8. 003 okhttp超时与缓存

    上文的介绍都没添加,如果要添加,则按照下面的方式设置. File sdcache = getExternalCacheDir(); int cacheSize = 10 * 1024 * 1024; ...

  9. 【Eclipse】Eclipse如何导出java项目为jar包

    1.首先确定要导出的项目 从项目结构可以看出,笔者的项目是一个Dynamic Java Project.com/db下面有一个config的数据库配置文件.WEB-INF/lib文件夹下面有依赖的ja ...

  10. JDBC 线程安全 数据库连接池

    jdbc 是线程安全的,但是,推荐一个线程用一个链接 JDBC is thread safe: It is quite OK to pass the various JDBC objects betw ...