<span>mysql5.6版本索引长度限制</span>

 

mysql5.6索引长度,最大676字节

因此建立联合索引时,需要注意长度,如下表能建立成功,如果去掉长度限制变成: unique key `name` (`name`,`wu`), 那么就会创建表失败。

 

create table `table_name` (
  `id` bigint(20) not null auto_increment comment '主键',
  `address` varchar(255) default 'work' ,
  `action` varchar(255) default null ,
  `city` varchar(255) default null ,
  `concurrent` int(11) default null ,
  `created` datetime not null,
  `created_by` varchar(255) not null,
  `modified` datetime not null,
  `modified_by` varchar(255) not null,
  `name` varchar(255) not null comment '名称',
  `wu` varchar(255) not null comment 'wuhan',
  primary key (`id`),
  unique key `name` (`name`(180),`wu`(60)),         
  key `idx_city` (`city`)
) engine=innodb default charset=utf8mb4 comment='信息';
全部评论

相关推荐

酷酷的喜马拉雅山:感觉这比一直在初筛不动的好多了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务