MYSQL - 警告:#1681 不推荐使用整数显示宽度

2022-01-05 00:00:00 mysql phpmyadmin

在 phpMyAdmin 中导入 mysql 转储时收到此警告:

I'm getting this warning when importing mysql dumps in phpMyAdmin:

警告:#1681 整数显示宽度已弃用,将在未来版本中删除.

我在 https://dev.mysql.com/worklog/task 上找到了这个/?id=13127

弃用数值数据类型的 ZEROFILL 属性和整数类型的显示宽度属性.

但我真的不明白这是什么意思.有人可以解释产生此警告的问题是什么,以及如何解决它.

but i don't really understand what it means. Can someone explain what is the problem generating this warning, and how to resolve it.

推荐答案

检查这个 数字类型属性 用于更完整的故事:

Check this Numeric Type Attributes for the much complete story:

MySQL 支持一个扩展,用于在类型的 base 关键字后面的括号中选择性地指定整数数据类型的显示宽度.例如,INT(4) 指定显示宽度为四位的 INT.应用程序可以使用此可选的显示宽度来显示宽度小于为列指定的宽度的整数值,方法是用空格向左填充它们.(也就是说,这个宽度存在于结果集返回的元数据中.是否使用取决于应用程序.)

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.)

显示宽度不限制列中可以存储的值的范围.它也不会阻止比列显示宽度更宽的值正确显示.例如,指定为 SMALLINT(3) 的列通常具有 -32768 到 32767 的 SMALLINT 范围,超出三位数字允许范围的值使用三位以上数字完整显示.

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.

因此,在 MySQL 的当前版本(撰写本文时为 8.0.17)之前,忽略此类警告应该是安全的.

So it shall be safe to ignore these kind of warning up to current version of MySQL (8.0.17 as of writing).

如果您想避免这些警告并安全操作,请将所有受影响的表更新为 INT(##)INT(即没有明确指定显示宽度).

If you'd like to avoid these warnings and play safe, update all your affected tables having column type definitions of something like INT(##) to INT (i.e. without explicitly specifying the display width).

相关文章