【Database】排错:Mysql5.6报错Specified key was too long; max key length is 767 bytes

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 在某个实验系统部署的过程中,出现mysql报错,是特定版本的处理错误,在查阅官网文档时得到解决方案

报错如下:

ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

 

image.png

 

错误是指超出索引字节的限制,并不是指字段长度限制。

MySQL 5.6官方文档内容如下

   By default, the index key prefix length limit is 767 bytes. See Section 13.1.13, “CREATE INDEX Syntax”. For example, you might hit this limit with a column prefix index of more than 255 characters on a TEXT or VARCHAR column, assuming a utf8mb3 character set and the maximum of 3 bytes for each character. When the innodb_large_prefix configuration option is enabled, the index key prefix length limit is raised to 3072 bytes for InnoDB tables that use DYNAMIC or COMPRESSED row format.

   Attempting to use an index key prefix length that exceeds the limit returns an error. To avoid such errors in replication configurations, avoid enablinginnodb_large_prefix on the master if it cannot also be enabled on slaves.

     The limits that apply to index key prefixes also apply to full-column index keys.

译文:

   默认情况下,索引键前缀长度限制为767字节。参见13.1.13创建索引语法。例如,如果在TEXTVARCHAR列上的列前缀索引超过255个字符,就可能会达到这个限制,假设使用utf8mb3字符集,每个字符的最大字节数为3字节。当innodb_large_prefix配置选项被启用时,对于使用动态或压缩行格式的InnoDB表,索引键前缀长度限制提高到3072字节。

   试图使用超过限制的索引键前缀长度将返回错误。为了避免在复制配置中出现这种错误,如果不能在从服务器上启用,请避免在主服务器上启用innodb_large_prefix

   适用于索引键前缀的限制也适用于全列索引键。

 

官网文档<https://dev.mysql.com/doc/refman/5.6/en/innodb-limits.html>

 

 

如果启用了系统变量innodb_large_prefix(默认启用,注意实验版本为MySQL  5.6.41,默认是关闭的,MySQL 5.7默认开启),则对于使用DYNAMICCOMPRESSED行格式的InnoDB表,索引键前缀限制为3072字节。如果禁用innodb_large_prefix,则对于任何行格式的表,索引键前缀限制为767字节。

 

 

解决:

1: 系统变量innodb_large_prefix为ON

2: 系统变量innodb_file_format为Barracuda

 

mysql> show variables like '%innodb_large_prefix%';
+---------------------+-------+
| Variable_name       | Value |
+---------------------+-------+
| innodb_large_prefix | OFF   |
+---------------------+-------+
1 row in set (0.00 sec)
mysql> set global innodb_large_prefix=on;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%innodb_file_format%';
+--------------------------+----------+
| Variable_name            | Value    |
+--------------------------+----------+
| innodb_file_format       | Antelope |
| innodb_file_format_check | ON       |
| innodb_file_format_max   | Antelope |
+--------------------------+----------+
3 rows in set (0.00 sec)
mysql> set global innodb_file_format=Barracuda;
Query OK, 0 rows affected (0.00 sec)

image.png

 

 

 

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
7月前
|
存储 关系型数据库 MySQL
环比、环比增长率、同比、同比增长率 ,占比,Mysql 8.0 实例(最简单的方法之一)(sample database classicmodels _No.2 )
环比、环比增长率、同比、同比增长率 ,占比,Mysql 8.0 实例(最简单的方法之一)(sample database classicmodels _No.2 )
344 1
|
7月前
|
SQL 前端开发 关系型数据库
全表数据核对 ,行数据核对,列数据核对,Mysql 8.0 实例(sample database classicmodels _No.3 )
全表数据核对 ,行数据核对,列数据核对,Mysql 8.0 实例(sample database classicmodels _No.3 )
149 0
全表数据核对 ,行数据核对,列数据核对,Mysql 8.0 实例(sample database classicmodels _No.3 )
|
7月前
|
关系型数据库 MySQL 数据库
mysql 8.0 递归(例子分享)(sample database classicmodels _No.4)
本文介绍了如何在MySQL8.0中使用递归查询处理部门表和员工表的树形结构数据,包括查看文档、准备数据、递归处理以及提取层级信息。作者通过示例展示了WITHRECURSIVE语句的应用及其在数仓中的结构表示。
96 2
|
7月前
|
安全 关系型数据库 MySQL
mysql8.0 正值表达式Regular expressions (sample database classicmodels _No.5)
本文介绍了MySQL8.0中的正值表达式及其相关函数,通过实例展示了如何使用正则表达式进行字符串匹配,并提出了关于执行效率的问题。
209 1
|
7月前
|
SQL 关系型数据库 MySQL
介绍5款 世界范围内比较广的 5款 mysql Database Management Tool
介绍5款 世界范围内比较广的 5款 mysql Database Management Tool
317 0
|
7月前
|
算法 关系型数据库 MySQL
复购率 mysql 实例(sample database classicmodels _No.1 )
复购率 mysql 实例(sample database classicmodels _No.1 )
120 0
|
9月前
|
存储 SQL 关系型数据库
在 MySQL 中使用 Drop Database
【8月更文挑战第11天】
334 0
在 MySQL 中使用 Drop Database
|
10月前
|
关系型数据库 MySQL 数据库
Mysqlbug-Could not create or access the registry key needed for the MySQL applicationto, TIMESTAMP w
Mysqlbug-Could not create or access the registry key needed for the MySQL applicationto, TIMESTAMP w
|
10月前
|
关系型数据库 MySQL 数据库
Relational Database Service RDS 各个版本
【7月更文挑战第12天】
78 0
|
12月前
|
关系型数据库 MySQL 数据库
MySQL8报错:Public Key Retrieval is not allowed
MySQL8报错:Public Key Retrieval is not allowed
5001 1

热门文章

最新文章

下一篇
oss创建bucket