Mysql优化

解决以下错误

[ERR] 1071 - Specified key was too long; max key length is 767 bytes
[ERR] 1709 - Index column size too large. The maximum column size is 767 bytes

说明:初步判断索引长度越界
innodb_large_prefix可以解决这个问题。该参数控制是否允许单列的索引长度超过767字节,有ON和OFF两个取值:ON :Innodb表的行记录格式是Dynamic或Compressed的前提下,单列索引长度上限扩展到3072个字节
OFF:Innodb表的单例索引长度最多为767个字节,索引长度超出后,主键索引会创建失败,辅助索引会被截断成为前缀索引

1.查看存储引擎为 InnoDB

show variables like '%storage_engine%';

mysql 数据量多 不走索引 mysql索引数据太大_sed

2.查看单列的索引长度控制

show variables like '%innodb_large_prefix%';

3.设置innodb_large_prefix参数

set global innodb_large_prefix=on;

mysql 数据量多 不走索引 mysql索引数据太大_取值_02

4.设置innodb_file_format参数

Antelope(不支持压缩) 和Barracuda(支持压缩)

show variables like '%innodb_file_format%';
set global innodb_file_format=Barracuda
set global innodb_file_format_max=Barracuda;

mysql 数据量多 不走索引 mysql索引数据太大_Dynamic_03