【MySQL】双字符主键过长 Specified key was too long; max key length is 767 bytes
2022/3/8 19:15:26
本文主要是介绍【MySQL】双字符主键过长 Specified key was too long; max key length is 767 bytes,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
MySQL版本:
这个情况在 8.0.28版本没有出现
报错如图
建表SQL:
DROP TABLE IF EXISTS `pt_dict_common`; CREATE TABLE `pt_dict_common` ( `DMBH` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '代码编号', `DMMC` varchar(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '代码名称', `DMLB` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '代码类别', `DMLBMC` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '代码类别名称', `SJDMBH` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '上级代码编号', `TIMELINE` datetime(0) NULL DEFAULT NULL COMMENT '时间戳', `SORT` bigint(20) NULL DEFAULT NULL COMMENT '排序', PRIMARY KEY (`DMBH`, `DMLB`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '通用字典' ROW_FORMAT = Dynamic;
问题排查定位在 声明的双主键上面:
DROP TABLE IF EXISTS `pt_dict_common`; CREATE TABLE `pt_dict_common` ( `DMBH` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '代码编号', `DMMC` varchar(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '代码名称', `DMLB` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '代码类别', `DMLBMC` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '代码类别名称', `SJDMBH` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '上级代码编号', `TIMELINE` datetime(0) NULL DEFAULT NULL COMMENT '时间戳', `SORT` bigint(20) NULL DEFAULT NULL COMMENT '排序', PRIMARY KEY (`DMBH`, `DMLB`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '通用字典' ROW_FORMAT = Dynamic;
默认字符双主键使用B+TREE
猜测是DMBH字段长度过大,在多次尝试后发现,长度设定为 191 可以创建
但是原因不知道是什么
这篇关于【MySQL】双字符主键过长 Specified key was too long; max key length is 767 bytes的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-02MySQL 3主集群搭建
- 2024-12-25如何部署MySQL集群资料:新手入门教程
- 2024-12-24MySQL集群部署资料:新手入门教程
- 2024-12-24MySQL集群资料详解:新手入门教程
- 2024-12-24MySQL集群部署入门教程
- 2024-12-24部署MySQL集群学习:新手入门教程
- 2024-12-24部署MySQL集群入门:一步一步搭建指南
- 2024-12-07MySQL读写分离入门:轻松掌握数据库读写分离技术
- 2024-12-07MySQL读写分离入门教程
- 2024-12-07MySQL分库分表入门详解