MySQL create table 建表错误Specified key was too long; max key length is 727 bytes

MySQL 创建表异常:

Specified key was too long; max key length is 727 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)

数据运维技术 » MySQL create table 建表错误Specified key was too long; max key length is 727 bytes