About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
MySQL stops CREATE INDEX, ALTER TABLE or CREATE TABLE with ERROR 1071 (42000) when an index key is longer, in bytes, than InnoDB allows. The Error Reference gives the text as "Specified key was too long; max key length is %d bytes", where the number is the limit that applies. For an InnoDB table that limit is 767 bytes with the COMPACT or REDUNDANT row format, or 3072 bytes with DYNAMIC or COMPRESSED. Multiply the indexed characters by the bytes per character, then change the row format or index fewer characters.
What the error means
The MySQL 8.4 InnoDB Limits page says "The index key prefix length limit is 3072 bytes for InnoDB tables that use DYNAMIC or COMPRESSED row format" and "767 bytes for InnoDB tables that use the REDUNDANT or COMPACT row format". It gives this example: "you might hit this limit with a column prefix index of more than 191 characters on a TEXT or VARCHAR column, assuming a utf8mb4 character set and the maximum of 4 bytes for each character."
Two other limits move the number. With a smaller InnoDB page size, the page says the maximum index key length "is 1536 bytes when the page size is 8KB, and 768 bytes when the page size is 4KB". For MyISAM tables, the CREATE INDEX page gives a prefix limit of 1000 bytes.
The units differ between the limit and the index definition. The CREATE INDEX page says "Prefix limits are measured in bytes", while prefix lengths written in CREATE TABLE, ALTER TABLE and CREATE INDEX "are interpreted as number of characters for nonbinary string types" and as bytes for binary string types. So email(191) on a utf8mb4 column means 191 characters, which is up to 764 bytes.
The same limit covers whole columns: "The limits that apply to index key prefixes also apply to full-column index keys." For a multicolumn index the page gives a maximum of 16 columns, so test the byte length of a multicolumn index rather than assuming a sum.
Whether this is an error depends on the SQL mode. The Server SQL Modes page says "Strict mode produces an error for attempts to create a key that exceeds the maximum key length. When strict mode is not enabled, this results in a warning and truncation of the key to the maximum key length."
Likely causes
| Cause | What you see | How to confirm |
|---|---|---|
Table uses COMPACT or REDUNDANT and the column is utf8mb4 |
Message says 767 | ROW_FORMAT is Compact or Redundant; characters multiplied by 4 exceed 767 |
A very long column indexed whole, even on DYNAMIC |
Message says 3072 | Characters multiplied by 4 exceed 3072, so more than 768 characters |
A table rebuilt without a stated ROW_FORMAT after the default changed |
Old index worked, new one fails | The row-format page says an operation that rebuilds a table "silently changes the row format" to innodb_default_row_format |
| Replica default differs from the source | Statement succeeds on the source, fails on the replica | Compare innodb_default_row_format on both servers |
| Smaller InnoDB page size | Message says 1536 or 768 | SELECT @@innodb_page_size; returns the page size in bytes (our own reading: 8192 for 8KB, 4096 for 4KB) |
Character set changed from utf8mb3 to utf8mb4 |
A 255-character prefix that worked now fails | 255 x 3 = 765 fits 767; 255 x 4 = 1020 does not |
Prove the cause before changing anything
All of these only read.
- Take the limit from the message: 767, 3072, 1536 or 768 points to the row of the table above.
- Read the table's row format. The manual gives two ways; the first is:
SHOW TABLE STATUS IN app\G
The second is SELECT NAME, ROW_FORMAT FROM INFORMATION_SCHEMA.INNODB_TABLES WHERE NAME='app/customers';. Read Row_format, or ROW_FORMAT.
- Read the default and the page size:
SELECT @@innodb_default_row_format;
SELECT @@innodb_page_size;
- Read the column's character set and length:
SHOW CREATE TABLE app.customers\G
- Do the arithmetic. Bytes = indexed characters x maximum bytes per character. The conversion page says
utf8mb3uses at most three bytes andutf8mb4at most four. Compare the result with the limit: on a 767-byte table, 767 / 4 = 191.75, so 191 characters is the most.
Fix
Choose one. A DYNAMIC table keeps the full key. A prefix index keeps the table as it is but changes what the index covers.
Move the table to the DYNAMIC row format
The row-format page says "DYNAMIC and COMPRESSED row formats support an index key prefix length of 3072 bytes".
First save the current state:
mysqldump --single-transaction --result-file=customers-before.sql app customers
Also save the row format and the table definition. Run these two read-only statements and copy both results into customers-format-before.txt:
SHOW TABLE STATUS IN app\G
SHOW CREATE TABLE app.customers\G
Risk: the next statement rebuilds the whole table app.customers. The row-format page says table-rebuilding operations include ALTER TABLE operations that use ALGORITHM=COPY or ALGORITHM=INPLACE where table rebuilding is required. Our own reading: changing ROW_FORMAT is such an operation, and a large table can take a long time and needs disk space for the copy.
Change the format by naming it:
ALTER TABLE app.customers ROW_FORMAT=DYNAMIC;
The statement names the format on purpose: the row-format page says "An explicitly defined ROW_FORMAT setting overrides the default row format".
To undo it: restore the row format recorded in customers-format-before.txt (shown here for a table that was COMPACT). A COMPACT table cannot hold an index key over 767 bytes, so any such index added since would first have to be removed; that removal is its own changing step and needs its own save and warning.
For this back-out only, first save the current state, which is the table as it stands after the change:
SHOW CREATE TABLE app.customers\G
Copy the result into customers-create-after.txt.
Risk: if you need to back out, the next statement rebuilds app.customers a second time, back to COMPACT. If an index longer than 767 bytes exists by then, it fails with ERROR 1071 until that index is removed.
Back-out only: restore the format, then read it again with SHOW TABLE STATUS IN app\G:
ALTER TABLE app.customers ROW_FORMAT=COMPACT;
Index a prefix of the column
First save the current state:
mysqldump --single-transaction --result-file=customers-before-index.sql app customers
Also save the table definition. Run this read-only statement and copy the result into customers-create-before.txt:
SHOW CREATE TABLE app.customers\G
Risk: the next statement adds a plain index on the first 191 characters of email. It does not enforce uniqueness. The CREATE INDEX page says that for a unique index on a prefix, "the column values must be unique within the prefix length". For a unique constraint, use the DYNAMIC fix above instead.
Add the index:
ALTER TABLE app.customers ADD INDEX idx_email (email(191));
To undo it: drop the index that was added, then read the table definition against customers-create-before.txt.
Risk: if you need to back out, the next statement drops the index idx_email that this fix added. Queries that used it become slower.
ALTER TABLE app.customers DROP INDEX idx_email;
For a table converted from utf8mb3 to utf8mb4, the manual says "you must either reduce the defined length of columns or indexes, or continue to use utf8mb3 rather than utf8mb4". Converting a table is covered in MySQL ERROR 1366 (HY000) Incorrect string value: how to store 4-byte characters with utf8mb4.
Example (illustrative): On db01, app.customers was created years ago with ROW_FORMAT=COMPACT. Its email column is VARCHAR(255) CHARACTER SET utf8mb4. ALTER TABLE app.customers ADD UNIQUE KEY uq_email (email); fails with ERROR 1071 (42000) and the limit 767. The key is 255 x 4 = 1020 bytes, which is 253 bytes over. SHOW TABLE STATUS IN app\G shows Row_format: Compact. After ROW_FORMAT=DYNAMIC the limit is 3072 and the 1020-byte key fits (3072 / 4 = 768 characters at most). The statement then succeeds.
Confirm the fix
SHOW TABLE STATUS IN app\GshowsRow_format: Dynamicif you changed the format.SHOW CREATE TABLE app.customers\Glists the new index with the length you intended.- The statement that failed now runs without
ERROR 1071.
What to watch afterwards
- A table rebuild without a stated
ROW_FORMATfollowsinnodb_default_row_format; the row-format page shows a table changing format that way. NameROW_FORMATin scripts that create tables. - The row-format page's example is a statement with a key prefix of 3070 characters that "succeeds on the source but fails on the replica" when the source default is
DYNAMICand the replica's isCOMPACT. Compare the two settings before you run DDL on a source. - A move from
utf8mb3toutf8mb4multiplies the byte length of every index by 4/3. The conversion page states that "the maximum length of a column or index key is unchanged in terms of bytes".
Read next
Related articles you may want next.
- TroubleshootingMySQL ERROR 1366 (HY000) Incorrect string value: how to store 4-byte characters with utf8mb4MySQL ERROR 1366 Incorrect string value for column: find whether the column or the connection is utf8mb3, then convert to utf8mb4 with a back-out.Read article
- Backup & RecoveryMySQL Shell dump utilities against mysqldump: consistency, users and restore timeHow MySQL Shell dump and load utilities differ from mysqldump on consistency, user accounts, checksums and restore time, from the MySQL 8.4 manuals.Read article
- TroubleshootingMySQL ERROR 1114 (HY000): The table is full: disk, MEMORY table limit or tablespaceMySQL ERROR 1114 (HY000) The table is full: check the disk, then MEMORY max_heap_table_size and InnoDB innodb_data_file_path, with back-outs.Read article
Risks and limits
- These commands have not been run or lab-tested.
- Both
ALTER TABLEstatements rebuild or modify a live table; take a dump that you can restore before either one. - The steps above are for InnoDB. The CREATE INDEX page gives a prefix limit of 1000 bytes for MyISAM and says the
NDBengine does not support prefixes. - For a multicolumn index the InnoDB Limits page gives a maximum of 16 columns; test the byte length of the index.
Sources
- 17.21 InnoDB Limits — MySQL 8.4 Reference Manual, Oracle, no date shown, accessed 3 December 2026
- 17.10 InnoDB Row Formats — MySQL 8.4 Reference Manual, Oracle, no date shown, accessed 3 December 2026
- 15.1.15 CREATE INDEX Statement — MySQL 8.4 Reference Manual, Oracle, no date shown, accessed 3 December 2026
- 12.9.8 Converting Between 3-Byte and 4-Byte Unicode Character Sets — MySQL 8.4 Reference Manual, Oracle, no date shown, accessed 3 December 2026
- 7.1.11 Server SQL Modes — MySQL 8.4 Reference Manual, Oracle, no date shown, accessed 3 December 2026
- 6.5.4 mysqldump — A Database Backup Program — MySQL 8.4 Reference Manual, Oracle, no date shown, accessed 3 December 2026
- 15.1.9 ALTER TABLE Statement — MySQL 8.4 Reference Manual, Oracle, no date shown, accessed 3 December 2026
- 15.7.7.11 SHOW CREATE TABLE Statement — MySQL 8.4 Reference Manual, Oracle, no date shown, accessed 3 December 2026
- Chapter 2 Server Error Message Reference — MySQL 8.4 Error Reference, Oracle, no date shown, accessed 3 December 2026
This article was originally published on .