我试图更好地理解MySQL系统是如何处理数据类型的,因此我用以下方式创建了一个表:
# Field, Type, Null, Key, Default, Extra
test1, tinyint(3) unsigned zerofill, YES, , ,
test2, smallint(5) unsigned zerofill, YES, , ,
test3, int(10) unsigned zerofill, YES, , ,
test4, bigint(20) unsigned zerofill, YES, , , 我最初只添加了没有自动填充的列:
create table test (
test1 tinyint,
test2 smallint,
test3 int,
test4 bigint
);桌子看起来是这样的:
# Field Type Null Key Default Extra
test1 tinyint YES
test2 smallint YES
test3 int YES
test4 bigint YES 但是,我通过alter添加了autofill属性,最后的结果是:
# Field Type Null Key Default Extra
test1 tinyint(3) unsigned zerofill YES
test2 smallint(5) unsigned zerofill YES
test3 int(10) unsigned zerofill YES
test4 bigint(20) unsigned zerofill YES 发布于 2021-02-13 02:49:10
在过去,INT(5)和INT是一样的。只有当ZEROFILL也被指定时,这个数字才有用。
在未来,ZEROFILL和这个数字将会消失。这种不兼容的变化在8.0.xx中预测了一段时间。你可能看到了朝着这个方向迈出的一步。
Zerofill很少被使用。存储在MEDIUMINT(5) UNSIGNED ZEROFILL中的美国邮政编码是我唯一能想到的现成的情况。
当Zerofill离开的时候,有一些解决你真正需要它的罕见情况的方法。
这个数字使许多人感到困惑。新手需要时间才能明白,这通常是没有用的。
虽然DESCRIBE和information_schema.TABLES很容易显示表的模式,但请养成使用SHOW CREATE TABLE的习惯;它以规范的形式将有用的信息组合在一起。
https://dba.stackexchange.com/questions/285321
复制相似问题