Specified key was too long; max key length is 3072 bytes
Production Risk
Low — DDL fails; no data loss.
ER_TOO_LONG_KEY (1074, SQLSTATE 42000) is raised when an index definition exceeds the storage engine's maximum key length. For InnoDB with innodb_large_prefix (MySQL 5.7+), the limit is 3072 bytes; for older configurations it is 767 bytes.
- 1Index on a VARCHAR column with a length that exceeds the byte limit (e.g., VARCHAR(255) with utf8mb4 = 1020 bytes)
- 2Composite index whose total column bytes exceed the limit
- 3innodb_large_prefix is disabled on MySQL 5.6
CREATE TABLE t (name VARCHAR(800) CHARACTER SET utf8mb4, INDEX idx_name (name));
expected output
ERROR 1074 (42000): Specified key was too long; max key length is 3072 bytes
Fix
Reduce the indexed column length or use a prefix index
WHEN Index exceeds the byte limit.
-- Use a prefix: CREATE TABLE t (name VARCHAR(800) CHARACTER SET utf8mb4, INDEX idx_name (name(191))); -- Or shorten the column: CREATE TABLE t (name VARCHAR(191) CHARACTER SET utf8mb4, INDEX idx_name (name));
Why this works
191 characters × 4 bytes/char (utf8mb4) = 764 bytes, just under the 767-byte legacy limit.
✕ Switch the column to latin1 to bypass the limit
Changing charset to fit an index loses multibyte character support; use a prefix index instead.
innodb_large_prefix is enabled by default, raising the limit from 767 to 3072 bytes for DYNAMIC and COMPRESSED row formats.
MySQL 8.0 — 1074 ER_TOO_LONG_KEY
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev