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

mysq索引的字段都太长了,解决办法:让mysql支持比较长的索引,然后在插入表的时候,添加ROW_FORMAT=DYNAMIC ,自动格式化索引。

  1. 数据库层面的修改
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;

  1. 建表语句的修改(直接使用navicat就不需要了)
-- 修改插入sql的语句添加ROW_FORMAT=DYNAMIC
create table idx_length_test_02
(
  id int auto_increment primary key,
  name varchar(255)
) 
ROW_FORMAT=DYNAMIC default charset utf8mb4;

原文地址:Mysql之Specified key was too long; max key length is 767 bytes

Logo

更多推荐