MEDIUMINT is a MySQL-specific integer type that occupies 3 bytes (24 bits) per row. In signed mode it stores values from -8,388,608 to 8,388,607. With the UNSIGNED attribute the range shifts to 0–16,777,215. MEDIUMINT is useful when SMALLINT’s 2-byte range is too small but INT’s 4-byte storage is excessive. You may specify an optional display width (M) for legacy applications; it does not affect the stored range and is ignored in MySQL 8.0 and newer when the ZEROFILL attribute is absent. MEDIUMINT can be combined with ZEROFILL to left-pad displayed values with zeros and implicitly add UNSIGNED. MEDIUMINT columns can be AUTO_INCREMENT and participate in indexes. Because MEDIUMINT is not part of the SQL standard, portability to other RDBMSs is limited. Overflow inserts or updates throw an out-of-range error unless strict SQL mode is disabled, in which case the value is clipped and a warning is issued.
M
(Integer) - Optional display width used only for formatting prior to MySQL 8.0.UNSIGNED
(Keyword) - Shifts the range to non-negative values (0|||16,777,215).ZEROFILL
(Keyword) - Pads displayed numbers with leading zeros to the display width and automatically sets UNSIGNED. If M is omitted, the default width is 10.TINYINT, SMALLINT, INT, BIGINT, UNSIGNED, ZEROFILL, AUTO_INCREMENT, STRICT SQL mode
MySQL 3.23
Signed MEDIUMINT ranges from -8,388,608 to 8,388,607. With UNSIGNED the range is 0–16,777,215.
Yes. MEDIUMINT uses 3 bytes per row, while INT uses 4 bytes. For large tables this can translate to significant disk and memory savings.
Absolutely. MEDIUMINT can serve as a primary key with AUTO_INCREMENT, provided the sequence will not exceed its numeric limit.
In strict SQL mode MySQL raises ERROR 1264 and the row is not inserted. In non-strict mode MySQL clips the value to the nearest boundary and issues a warning.