mysql规范

 

l   不建议对过长的VARCHAR类型字段建立索引:MySQLvarchar索引只支持不超过768个字节,UTF8是三字节,即:768/3=256,所以字段最长为255

mysql> create table test3

    -> (id int not null primary key,

    -> name varchar(256));

Query OK, 0 rows affected (0.10 sec)

mysql> create index idx_test_name on test3(name);

ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

mysql> create table test3

    -> (id int not null primary key,

    -> name varchar(255));

Query OK, 0 rows affected (0.10 sec)

mysql> create index idx_test_name on test3(name);

Query OK, 0 rows affected (0.11 sec)

Records: 0  Duplicates: 0  Warnings: 0

你可能感兴趣的:(mysql规范)