MySQL VARCHAR(255) UTF8 is too long for key, but max length is 1000 bytes

前端 未结 3 1431
一生所求
一生所求 2021-01-31 07:34

I know there have been plenty of questions about this, but I think my math is right.

  • MySQL reserves 3 bytes per UTF8 character.
  • MyISAM allows keys of leng
3条回答
  •  攒了一身酷
    2021-01-31 08:29

    MySQL reserves the max amount for a UTF8 field which is 4 bytes, so that is why you are blowing past the 1000 byte limit. My recommendation is to create the varchar at less than 255 or create it without UTF8.

    Both of those solutions are probably not right for you or you would have already tried that.

    The only other solution I can think of is to split the column into 2 small columns and create an unique index on both of those fields, but I believe that you would get the same error as above.

    Since you probably need UTF8, I would seriously look at reducing the varchar(255) column down a little to 250 (or 249) to make this work.

提交回复
热议问题