mysql中int 5_mysql中int(5)的含义

本文详细解析了MySQL中INT(M)的真实含义,并通过实验验证了M参数并不影响整数类型的存储长度,而是用于定义显示宽度。同时,文中探讨了zerofill属性的作用及其实现原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目标:区分int(5)与int的区别

准备:mysql 5.7.18,官方文档:https://dev.mysql.com/doc/refman/5.7/en/numeric-type-syntax.html

步骤1:

官方文档中的描述:

For integer data types, M indicates the maximum display width. The maximum display width is 255. Display width is unrelated to the range of values a type can store, as described in Section 11.1.6, “Numeric Type Attributes”.

对于整数类型,M表示【展示宽度】的最大值。上限是255。展示宽度与整数类型可以存储值的范围没有关系,如11.1.6中所描述的那样。

步骤2:

创建测试表

cd570e96ed4c535cf3e3be63661ddfa7.png

步骤3:

插入测试数据

64fdd0037226f12f0cdacbe63c959f83.png

步骤4:

查询数据

bef91a6ae0b8de9bf3881de01399dcb0.png

结论:

int(5) 中5与存储的数据长度或大小没有关系,验证 column: int1。

如果使用了zerofill 属性,且存储的整数长度不足5,则使用0进行补位,验证 column:zero_fill1。

如果没有使用zerofill 属性,则 int(M) 中的 M实际上是不生效的。验证 column: int2。

超过了M长度,zerofill 属性当然也不生效。验证 column: zero_fill2。

参考:

https://nexladder.com/blog/what-does-int11-means-in-mysql/#:~:text=most%20of%20the%20developer%20think,with%2011%20digits%20in%20length.&text=in%20int(11)%2C%2011,character%20that%20can%20be%20stored.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值