Ispirer Ispirer
 


Ispirer Home Page Ispirer SQLWays Product Page - Migration to MySQL Request SQLWays

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:

  • Changing the size of some columns. For example, if VARCHAR(300) is used to store last names, you can reduce its size to 100 with minimal risk of data loss.
  • Specifying the partial column length for the character columns in the key. For example, for VARCHAR(1000) column, you can specify only 100 characters to be used in the key.
ALTER TABLE department
  ADD PRIMARY KEY (id, name(100));

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

  • Using a different set of columns for the key.


Ispirer Home Page Ispirer SQLWays Product Page - Migration to MySQL Request SQLWays

sqlways/troubleshooting-guide/mysql/import/key-too-long.txt · Last modified: May 07, 2018, 03:15:34 PM (external edit)
 
© 1999-2018, Ispirer Systems Ltd.
All Rights Reserved.  Privacy Statement