During the design of MySQL database fields today, the prompt is always prompted during table creation.MySQL:
Error 1071 (42000): specified key was too long; max key length is 767 bytes.At first, I didn't figure out why, because by default, MySQL restricts the length of the varchar type to between 0 and 65535. Later, I checked other attributes of this field carefully, if the unique attribute is removed, no such error message is returned, which complies with the 65535-byte length limit described in the official document.
I personally suspect that after the field is set to unique, MySQL will automatically establish the unique index on this field, and there will be System overhead for maintaining the unique index, so this problem will occur, on the one hand, a unique index is provided to avoid overhead issues caused by long index maintenance.
Another problem in MySQL is that UTF-8 occupies three bytes by default and the GBK encoding method occupies two bytes, therefore, if your character set is encoded in UTF-8 format, 767/3 = 255 characters can only be up to 255 characters, not 767 characters.