Specified key was too long; max key length is 767 bytes

mysql创建表时报错:

Specified key was too long; max key length is 767 bytes


 

原因是字段设置长度限制了767个字节 ,一个varchar占用4个字节,

解决办法:

  设置varchar字符长度不能超过191 (191*4=764)

  或者启用innodb_large_prefix,限制值会增加到3072

mysql> set global innodb_file_format = BARRACUDA;
Query OK, 0 rows affected (0.00 sec)
 
mysql> set global innodb_large_prefix = ON;
Query OK, 0 rows affected (0.00 sec)

 

posted @ 2020-12-17 16:04  子寒子寒  阅读(284)  评论(0)    收藏  举报