When encountering the MySQL error 1071: Specified key was too long; max key length is 767 bytes, the immediate action is to check and potentially adjust the column data types or the specific index length to be within the limit. If using a character set like utf8mb4, where each character can take up to 4 bytes, you might exceed the limit with a relatively small number of characters.
SHOW CREATE TABLE your
table
name;
To adjust the index length, modify the index declaration, specifying a prefix length that keeps the total size under 767 bytes. For a utf8mb4 column, this would look like:ALTER TABLE your
table
name MODIFY COLUMN your
column
name VARCHAR(191);
Or, for creating a new index with a specified key length:CREATE INDEX index
name ON your
table
name(your
column_name(191));
If adjusting the column size or the index length is not feasible, consider changing the table's character set to utf8, which requires fewer bytes per character if internationalization concerns permit this change.
Please note, steps involving changes to system variables or file formats should be approached with caution and ideally tested in a non-production environment first.
Let Dr. Droid create custom investigation plans for your infrastructure.
Book Demo