DBAtlas · Database operations atlas

1071: Specified key was too long; max key length is 767 bytes

MySQL

What does it mean?

The index (or key) being created exceeded the maximum allowed length in bytes. With multibyte character sets in particular, VARCHAR indexes reach this limit quickly.

Why does it happen?

An index on a wide VARCHAR column with utf8mb4 (4 bytes per character); an old InnoDB row format (REDUNDANT/COMPACT; on 5.7 and earlier also a disabled innodb_large_prefix); the total length of a multi-column composite index exceeding the limit; a large primary key.

How to fix it

Shorten the indexed column length or use a prefix index: CREATE INDEX idx ON my_table (my_column(191)); Move to the 3072-byte limit with the DYNAMIC/COMPRESSED row format (DYNAMIC is the default in MySQL 8.0; innodb_large_prefix was removed in 8.0 and is only needed on 5.7 and earlier). If needed, review the column's character set/length.

Open in DBAtlas →

More from this engine