`
eyesmore
  • 浏览: 363451 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

阅读更多

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

 

CREATE TABLE foo ( bar INT(20) ZEROFILL );
INSERT INTO foo (bar) VALUES (1234);
SELECT bar from foo;

+----------------------+
| bar                  |
+----------------------+
| 00000000000000001234 |
+----------------------+
 

 

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的数字类型(1B,2B,3B,4B,8B都有)

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

  • 大小: 6.8 KB
分享到:
评论

相关推荐

    对比MySQL中int、char以及varchar的性能

    关于数据库的谣言也有不少,比如“int性能比char高很多”。 我最近针对int、long、char、varchar进行了一次性能测试,发现它们其实并没有太大的性能差距: 备注:c8=char(8), s8=varchar(8), i8=(bigint), c4=char(4...

    MySQL数据库中把int转化varchar引发的慢查询

    最近一周接连处理了2个由于int向varchar转换无法使用索引,从而引发的慢查询。 CREATE TABLE `appstat_day_prototype_201305` ( `day_key` date NOT NULL DEFAULT '1900-01-01', `appkey` varchar(20) NOT NULL ...

    mysql中int、bigint、smallint 和 tinyint的区别详细介绍

    最近使用mysql数据库的时候遇到了多种数字的类型,主要有int,bigint,smallint和tinyint;接下来将详细介绍以上三种类型的应用

    中国5级省市县镇村MySQL完整数据-SQL文件

    中国五级省市县镇村的MySQL完整数据,已经做成SQL文件,带建表语句 /* Navicat MySQL Data Transfer Target Server Type : MYSQL Target Server Version : 50612 File Encoding : 65001 Date: 2017-03-07 16:05:...

    PHP和MySql中32位和64位的整形范围是多少

    一个字节有8位,所以32位int型占用32位/8位=4个字节,64位int型占用64位/8位=8个字节. ...64位Ubuntu 14.04,PHP_INT_MAX的值为9223372036854775807,跟MySQL中有符号的bigint型的最大值一样. 32位Ubuntu 14.04,PH

    JDBC数据类型与数据库字段对应表——mysql篇

    JDBC数据类型与数据库字段对应表——mysql篇 数值型 整型 JDBC tinyint java.lang.Integer smallint mediumint java.lang.Long int bigint java.math.BigInteger

    Mysql数据库设计.pdf

    较⼩的整数 有符号值:-32768 MEDIUMINT 3字节 中等⼤⼩的整数 有符号值: INT 4字节 标准整数 有符号值: BIGINT 8字节 ⼤整数 有符号值: FLOAT 4字节 单精度浮点数 有符号值: DOUBLE 8字节 双精度浮点数 有符号...

    mysql全国地区详细数据表带街道社区村庄

    `province_id` bigint(20) unsigned NOT NULL, `province_name` char(64) NOT NULL, `city_id` bigint(20) unsigned NOT NULL, `city_name` char(64) NOT NULL, `county_id` bigint(20) unsigned NOT NULL, `...

    MySQL 省市区街道sql文件

    `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', `create_date` datetime NOT NULL COMMENT '创建日期', `modify_date` datetime NOT NULL COMMENT '修改日期', `version` bigint(20) NOT NULL COMMENT ...

    消息聊天系统MySQL表设计-消息系统数据库设计.pdf

    消息聊天系统MySQL表设计_消息系统数据库设计 1、新建platform_info表,此表存储调⽤消息平台⽅应⽤信息 CREATE TABLE IF NOT EXISTS `platform_info` ( `id` int(11) NOT NULL AUTO_INCREMENT, `platform_code` ...

    MySQL 数据类型 详解

    MySQL数据类型 含义(有符号) tinyint(m) 1个字节 范围(-128~127) smallint(m) 2个字节 范围(-32768~32767) mediumint(m) 3个字节 范围(-8388608~8388607) int(m) 4个字节 范围(-2147483648~2147483647) ...

    MYSQL安装包官方试用版

    这说明MySQL簇中的表中的VARCHAR列的行为如同类型CHAR(不同的是每个记录仍然有一个额外字节空间)。例如,在Cluster表中,声明为VARCHAR(100)的列中的每个记录存储时将占用101个字节,无论实际存储的记录中的字符串的...

    干货题目 mysql 面试题集锦 常见练习题目 考试题目 共28页.pdf

    O),salary bigint,deptid int); 插入实验数据: mysql> insert into employee921 values(null,'zs',1000,1),(null,'ls',1100, l ),(null ,'ww', 1100, l ),(null,'zl',900, l) ,(null,'zl', 1000,2), (null,'zl',900...

    MySQL数据库:表的字段类型.pptx

    数据库和表的创建与管理 表的字段类型 课程目标 掌握 —— 不同数据类型的选择。 理解 —— MySQL支持的数据类型;...每个时间类型有一个有效值范围和一个"零"值,当指定不合法的MySQL不能表示的值时使

    mysql创建表方法.zip

    • 整数类型:TINYINT、SMALLINT、MEDIUMINT、INT、BIGINT。 • 浮点数和定点数类型:FLOAT、DOUBLE、DECIMAL。 • 字符串类型:CHAR、VARCHAR、TEXT、TINYTEXT、MEDIUMTEXT、LONGTEXT。 • 日期和时间类型:DATE、...

    简单了解mysql存储字段类型查询效率

    1、TINYINT,SMALLINT,MEDIUMINT,INT,BIGINT,分别用8,16,24,32,64存 2、整数都有UNSIGNED可选属性 (拿tinyint字段来举例,unsigned后,字段的取值范围是0-255,而signed的范围是-128 – 127。 那么如果我们在...

    2019city.zip

    网上的大多数都是2019年以前的老版数据,2019年全国做过新的行政区划划分,故而有了我这篇资源。 表结构如下: CREATE TABLE `city` ( `id` bigint(20) NOT NULL COMMENT '区划代码', `name` varchar(50) DEFAULT ...

    (mysql面试题)MySQL中的基本数据类型及其特点及代码示例.txt

    - SMALLINT:占用2个字节,取值范围为-32,768到32,767(有符号)或0到65,535(无符号)。 - MEDIUMINT:占用3个字节,取值范围为-8,388,608到8,388,607(有符号)或0到16,777,215(无符号)。 - INT:占用4个字节...

    中国地区 省市三级联动 sql脚本 数据库 mysql

    `ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', `FULLNAME` varchar(255) COLLATE utf8_bin NOT NULL COMMENT '全称', `GRADE` int(11) NOT NULL COMMENT '层级', `NAME` varchar(255) COLLATE utf8_...

    中国城市sql数据表,导入就可以使用

    中国所有城市数据元表,导入数据库就可以使用,mysql,Oracle都可以用 CREATE TABLE `city` ( `id` int(11) NOT NULL AUTO_INCREMENT, `province_id` bigint(20) UNSIGNED NOT NULL, `province_name` char(64) ...

Global site tag (gtag.js) - Google Analytics