阿里云 RDS Specified key was too long; max key length is 767 bytes 解决方案
Specified key was too long; max key length is 767 bytes 出现的原因为:
MySQL 建立索引键前缀限制为767字节,而 innodb_large_prefix
默认为关闭的,如果打开 innodb_large_prefix
配置,限制为 3072字节。
MySQL 5.X 解决方案
依次执行以下命令
mysql> set global innodb_file_format = BARRACUDA;
mysql> set global innodb_large_prefix = ON;
不需要重启,再次创建索引,如果不提示 Specified key was too long; max key length is 767 bytes
就是解决了。如果不行,那么再修改表
//修改表row_format 为 dynamic 或者 compressed
alter table table row_format=dynamic;
//或者
alter table table row_format=compressed;
再次测试即可。
阿里云RDS 解决方案
登录阿里云后台 ----> 选择 RDS 管理 ---> 列表后面有”管理“ ----> 左侧选择【参数设置】---> 进去搜索【innodb_large_prefix
】如下图:
把默认的OFF
修改为ON
,图上是我已经修改了。
注意:修改后右上角【提交参数】后方可生效,不用重启RDS。
然后执行命令:
如果是已经存在的表,在链接了 MySQL 的客户端中执行其中一条命令。
//修改表row_format 为 dynamic 或者 compressed
alter table table row_format=dynamic;
//或者
alter table table row_format=compressed;
如果是新表:
create table table_name
(
id int auto_increment primary key,
name varchar(255)
)
ROW_FORMAT=DYNAMIC default charset utf8mb4;
其实就是设置 ROW_FORMAT=DYNAMIC
。
版权所属:SO JSON在线解析
原文地址:https://www.sojson.com/blog/351.html
转载时必须以链接形式注明原始出处及本声明。
如果本文对你有帮助,那么请你赞助我,让我更有激情的写下去,帮助更多的人。