List:General Discussion« Previous MessageNext Message »
From:Martijn Tonies Date:January 7 2004 10:32am
Subject:Re: max length of primary key
View as plain text  
Hi,

> I have a problem when creating a table:
>
>
> CREATE TABLE test (
>     test_key varchar(255) NOT NULL default '',
>     test_value text NOT NULL,
>     PRIMARY KEY (test_key) ) TYPE=MYISAM;
>
> It then report error:
>
> mySQL Error: Specified key was too long. Max key length is 500
>
> Why the varchar exceeded 500?
> I have a "set-variable    = default-character-set=utf8" in my.cnf,  maybe
> this is the cause of error?
> And is there way to increase this 500 value?  Or I must use InnoDB then?

Apparently, the "500" number is "bytes". Assuming UTF8 takes
at least two bytes/character, then yes, your VARCHAR(255)
takes up more than 500 bytes.

With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com

Thread
max length of primary keyFrancis Mak7 Jan
  • Re: max length of primary keyMartijn Tonies7 Jan