mysqldude
Error codes › 1071

MySQL & MariaDB error 1071: Specified key was too long

Error messageSpecified key was too long; max key length is … bytes
Example from our test runs: Specified key was too long; max key length is 3072 bytes (5.7.44)

An index would be longer than the storage engine allows (3072 bytes for InnoDB with DYNAMIC rows, 767 with the old COMPACT format). utf8mb4 needs 4 bytes per character, so VARCHAR(1000) can't be fully indexed.

MySQLMariaDB
SymbolER_TOO_LONG_KEYER_TOO_LONG_KEY
SQLSTATE4200042000
TypeServer errorServer error
Versionsevery release since 5.0 activeevery release since 5.5 active

What it means

Specified key was too long; max key length is 3072 bytes. The limit is in bytes, and InnoDB reserves the maximum bytes per character: 4 for utf8mb4, 3 for utf8mb3. So an index on VARCHAR(1000) CHARACTER SET utf8mb4 needs 4,000 bytes.

Row format / version Max index prefix
DYNAMIC or COMPRESSED (default since MySQL 5.7.9 / MariaDB 10.2) 3072 bytes, so VARCHAR(768) in utf8mb4
COMPACT or REDUNDANT, or MySQL 5.6 defaults 767 bytes, so VARCHAR(191) in utf8mb4

Why it happens

  • Converting a table from utf8/latin1 to utf8mb4: existing indexes grow by a third or more.
  • Indexing long URL, path or email columns.
  • MySQL 5.6 or ROW_FORMAT=COMPACT tables: that is where the famous VARCHAR(191) advice comes from. MariaDB reports the COMPACT case as 1709.
  • Behaviour differs by version (from our tests): MySQL 5.7+ rejects the index with 1071; MySQL 5.6 and MariaDB instead silently create a shorter prefix index for a non-unique key (5.6 with a warning, MariaDB with only a note). For a UNIQUE key MariaDB 10.4+ builds a hidden hash index instead of failing.

How to fix it

  • Index a prefix: KEY (url(191)). A prefix can’t enforce full-value uniqueness, though.
  • Shorten the column to what you really need, e.g. VARCHAR(255) for email.
  • Use ROW_FORMAT=DYNAMIC (the default on current versions) to get the 3072-byte limit.
  • For uniqueness on long values, index a hash: a generated column url_hash BINARY(32) AS (UNHEX(SHA2(url, 256))) STORED with a UNIQUE key on it.

Reproduce it yourself

These steps are the exact test our harness runs. Use a scratch server, never production.

  1. Connect with mysql -u root -p and create a scratch database:

    CREATE DATABASE demo;
    USE demo;
  2. Run:

    CREATE TABLE t (url VARCHAR(1000) CHARACTER SET utf8mb4, KEY (url)) ENGINE=InnoDB;

You get: Specified key was too long; max key length is 3072 bytes(9.7.4)

Verified fixes

  1. Index a prefix of the column, or shorten it

    CREATE TABLE t (url VARCHAR(1000) CHARACTER SET utf8mb4, KEY (url(191))) ENGINE=InnoDB;
    SELECT COUNT(*) FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't';

Tested on

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
Index a long utf8mb4 VARCHAR (4 bytes per character); MySQL 5.6 and MariaDB silently index a prefix instead
repro
≠✓ 1071✓ 1071✓ 1071✓ 1071≠≠≠≠
Same column as a UNIQUE key (MariaDB 10.4+ uses a hidden hash index)
version check
✓ 1071✓ 1071✓ 1071✓ 1071✓ 1071≠≠≠≠
VARCHAR(255) utf8mb4 index (1020 bytes) with ROW_FORMAT=COMPACT: 767-byte limit (MariaDB reports 1709)
version check
≠✓ 1071✓ 1071✓ 1071✓ 1071✓ 1709✓ 1709✓ 1709✓ 1709
Index a prefix of the column, or shorten it
fix
✓✓✓✓✓✓✓✓✓
Index a long utf8mb4 VARCHAR (4 bytes per character); MySQL 5.6 and MariaDB silently index a prefix instead repro
MySQL 5.6≠5.7✓ 10718.0✓ 10718.4✓ 10719✓ 1071
MariaDB 10.6≠10.11≠11.4≠11.8≠
Same column as a UNIQUE key (MariaDB 10.4+ uses a hidden hash index) version check
MySQL 5.6✓ 10715.7✓ 10718.0✓ 10718.4✓ 10719✓ 1071
MariaDB 10.6≠10.11≠11.4≠11.8≠
VARCHAR(255) utf8mb4 index (1020 bytes) with ROW_FORMAT=COMPACT: 767-byte limit (MariaDB reports 1709) version check
MySQL 5.6≠5.7✓ 10718.0✓ 10718.4✓ 10719✓ 1071
MariaDB 10.6✓ 170910.11✓ 170911.4✓ 170911.8✓ 1709
Index a prefix of the column, or shorten it fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9
What the warnings and failures say (3)
  • Index a long utf8mb4 VARCHAR (4 bytes per character); MySQL 5.6 and MariaDB silently index a prefix instead (MySQL 5.6, MariaDB 10.6, MariaDB 10.11, MariaDB 11.4, MariaDB 11.8): expected error 1071 did not occur
  • Same column as a UNIQUE key (MariaDB 10.4+ uses a hidden hash index) (MariaDB 10.6, MariaDB 10.11, MariaDB 11.4, MariaDB 11.8): expected error 1071 did not occur
  • VARCHAR(255) utf8mb4 index (1020 bytes) with ROW_FORMAT=COMPACT: 767-byte limit (MariaDB reports 1709) (MySQL 5.6): expected error [1071, 1709] did not occur

Related errors

  • 1709 ER_INDEX_COLUMN_TOO_LONG
  • 1170 ER_BLOB_KEY_WITHOUT_LENGTH
  • 1366 ER_TRUNCATED_WRONG_VALUE_FOR_FIELDexplained