Ispirer Website Ispirer Capabilities: MySQL Migration Free Trial

ERROR 1071 (42000): Specified Key was Too Long; Max Key Length is 767 Bytes

Symptoms

During the import to MySQL, when you create a key for a InnoDB table, the “ERROR 1071 (42000)” error arises. For example,

CREATE TABLE department 
  (
    id INT,
    name VARCHAR(1000)
   );

ALTER TABLE department
  ADD PRIMARY KEY (id, name);

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

Cause

The maximum key length for the MySQL database for InnoDB Engine is 767 bytes. The key length includes the sum lengths of all the columns included in the key.

Solutions

There are several solutions for this issue:

ALTER TABLE department
  ADD PRIMARY KEY (id, name(100));

In this example only 100 bytes of the NAME column participate in the primary key.


If you have any other questions, please contact us: support@ispirer.com