您的当前位置:首页正文

mysql索引 键长度 1071 - Specified key was too long; max key length is 3072 bytes

2024-11-28 来源:个人技术集锦

mysql索引 键长度

开发中两个 varchar 1000 的字段进行关联,作为一个mysql索引小白,就直接去表里加一个正常的索引,这会报了一个错,说我索引长度过长。在网上搜了都是说要改mysql配置文件。偶然看到一个大佬发的文章,才知道mysql这个索引长度是这样一个用法。

mysql报的错:1071 - Specified key was too long; max key length is 3072 bytes

SELECT
 ROUND(SUM(LENGTH(`school_unit_title`)<10)*100/COUNT(`school_unit_title`),2) AS pct_length_10,
 ROUND(SUM(LENGTH(`school_unit_title`)<20)*100/COUNT(`school_unit_title`),2) AS pct_length_20,
 ROUND(SUM(LENGTH(`school_unit_title`)<50)*100/COUNT(`school_unit_title`),2) AS pct_length_50,
 ROUND(SUM(LENGTH(`school_unit_title`)<80)*100/COUNT(`school_unit_title`),2) AS pct_length_80,
 ROUND(SUM(LENGTH(`school_unit_title`)<100)*100/COUNT(`school_unit_title`),2) AS pct_length_100
FROM `z_school_unit`;
显示全文