17

I can't create index on varchar(500).

MySQL: Specified key was too long; max key length is 1000 bytes

Teun Zengerink
  • 4,277
  • 5
  • 30
  • 32
ZA.
  • 10,107
  • 10
  • 37
  • 39
  • 1
    The complete answer to this question is given [here](http://stackoverflow.com/questions/1814532/1071-specified-key-was-too-long-max-key-length-is-767-bytes/1814594#1814594). – dma_k Nov 10 '11 at 09:07
  • Here is 1 line short and completely working solution: http://stackoverflow.com/questions/1814532/1071-specified-key-was-too-long-max-key-length-is-767-bytes/22873006#22873006 – Raza Ahmed Apr 04 '14 at 21:06

1 Answers1

24
latin1 = 1 byte = 1 character
uft8 = 3 byte = 1 character
gbk = 2 byte = 1 character
ZA.
  • 10,107
  • 10
  • 37
  • 39
  • 4
    Shouldn't utf-8 characters be of variable length (1-4), depending on the unicode code point? – Svante Jun 24 '09 at 11:34
  • 5
    The maximum number of bytes needed for one utf8 character is 3, and MySQL must make provision for all of the characters in te field to be the maximum number of bytes. – Jrgns Apr 28 '10 at 03:22
  • 1
    Except the maximum number of bytes on UTF-8 is 4 bytes. MySQL made this stupid, stupid, stupid, horribly evil decision to make utf8 only support 3 bytes. The "real" UTF-8 compatible charset is utf8mb4, only supported on MySQL 5.6. – SineSwiper Nov 06 '14 at 14:42