MySQL 报错:[Err] 1071 - Specified key was too long; max key length is 767 bytes

[Err] 1071 - Specified key was too long; max key length is 767 bytes

 

 

这个会出现在MySQ5.7以下版本 因为没有启用innodb_large_prefix

MySQL 5.6:

 

 

 MySQL 5.7:

 

简单办法:如果要求不是很高 ,也可以直接把表字段varchar(255)设置为varchar(64) 

 

 

另外一种:修改配置 (重启服务会失效)

mysql> show variables like '%innodb_large_prefix%';
+---------------------+-------+
| Variable_name       | Value |
+---------------------+-------+
| innodb_large_prefix | OFF   |
+---------------------+-------+
1 row in set

mysql> set global innodb_large_prefix=on;
Query OK, 0 rows affected

mysql> show variables like '%innodb_large_prefix%';
+---------------------+-------+
| Variable_name       | Value |
+---------------------+-------+
| innodb_large_prefix | ON    |
+---------------------+-------+
1 row in set

 

posted @ 2021-12-13 15:18  yvioo  阅读(1225)  评论(0编辑  收藏  举报