https://dev.mysql.com/doc/refman/8.0/en/numeric-type-attributes.html
MySQL supports an extension for optionally specifying the display width of integer data types in parentheses following the base keyword for the type. For example, INT(4) specifies an INT with a display width of four digits. 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. (That is, this width is present in the metadata returned with result sets. Whether it is used is up to the application.)
The display width does not constrain the range of values that can be stored in the column. Nor does it prevent values wider than the column display width from being displayed correctly. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range permitted by three digits are displayed in full using more than three digits.
When used in conjunction with the optional (nonstandard) ZEROFILL attribute, the default padding of spaces is replaced with zeros. For example, for a column declared as INT(4) ZEROFILL, a value of 5 is retrieved as 0005.
我的理解是这样的,M为显示宽度,和数据真实宽度无关,甚至可以超出字段允许的最大宽度。当存储的数据宽度小于M时,查询结果会在数据左侧填充空格直到宽度等于M。当字段设置zerofill时,填充的空格会被替换成0。这个选项仅影响显示结果,不会影响真实存储的数据。
这个理解,尤其是加粗的地方到底对不对,因为我怎么导出也没让查询出来的数据显示出来填充的空格。
此外还有个问题,当zerofill属性作用与浮点数列如double(6,3)时是什么效果,官方文档好像没有提及。