Mysql入门到精通 (Specified key was too long; max key length is 767 bytes)

1、前言

今天在创建索引的时候报了个错:Specified key was too long; max key length is 767 bytes,
当时找了资料,也没太好用啊,导致这个问题的原因索引的字段都太长了,mysql受不了,解决方法就是,让mysql支持比较长的索引,然后在插入表的时候,添加ROW_FORMAT=DYNAMIC ,自动格式化索引。或者把索引字段的长度调小。

2、效果演示

在这里插入图片描述

3、查看数据库信息

show variables like 'innodb_large_prefix';  
show variables like 'innodb_file_format';

--修改最大索引长度限制
set global innodb_large_prefix=1; 
set global innodb_file_format=BARRACUDA;
-- 添加
set global innodb_file_format_max=BARRACUDA;

4、修改插入sql的语句添加ROW_FORMAT=DYNAMIC

在这里插入图片描述

发布了136 篇原创文章 · 获赞 30 · 访问量 21万+

猜你喜欢

转载自blog.csdn.net/qq_33029793/article/details/103045188