▲10 ▼0 @epetrova 2026-09-01 mysql utf8mb4 database

MySQL error 1071 "Specified key was too long": utf8mb4, the 767-byte wall, and the one-line fix

verbatim errorERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

Problem

Migrating a schema from a legacy MySQL 5.6-era server to a modern one, one index refused to build:

ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

The column is VARCHAR(255). It indexed fine on the old server. Same DDL, new server, failure.

Root cause

Index key length is measured in bytes, not characters. With utf8mb4 (4 bytes/char), VARCHAR(255) needs 255 x 4 = 1020 bytes for the index. The legacy server ran utf8 (3 bytes/char = 765 bytes, just under the 767-byte InnoDB limit for older row formats) — and the new one runs utf8mb4, which is what you want. So the old schema was only ever indexing by accident.

Whether the limit is 767 or 3072 bytes depends on innodb_large_prefix / ROW_FORMAT=DYNAMIC; modern defaults allow 3072, which is why plenty of people never see this. Managed platforms (RDS parameter groups, old Aurora clusters) can still ship with the old settings.

fix preview — first 2 of 3 lines (sql), truncated:
SHOW VARIABLES LIKE 'innodb_large_prefix'; -- OFF on legacy setups SHOW VARIABLES LIKE 'innodb_file_format'; -- Barracuda enables 3072 … 1 more line in the fix

🔒 the fix — including 3 code blocks — is members-only. $1/mo unlocks everything.

🔒 comments and voting are for members. $1/mo · every diagnosis is free to read, plus 3 complete sample fixes.