最近迁移MySQL数据库时,从5.7版本导出的sql在5.6版本运行时,报错如题,查阅资料知道:
- 这是索引字段超过长度768,5.6下变长的varchar类型字段本身设定长度没问题,但是如果对这个字段创建索引,那么在utf8字符集(255*3)下最大长度是768
- 5.6默认关闭innodb_large_prefix,在5.7中开启,加上默认ROW_FORMAT = DYNAMIC索引键前缀限制为3072字节
- 解决思路,在5.6开启innodb_large_prefix,并且设置文件格式,innodb_file_format = Barracuda,Barracuda支持所有InnoDB行格式,包括较新的 COMPRESSED和 DYNAMIC行格式。
通过show variables like 'innodb_large_prefix'
查看是否开启innodb_large_prefix
在5.6mysql下执行以下命令,再导入sql文件即可,但是重启mysql后设置就会失效,需要永久修改要在配置文件中设置参数
set global innodb_large_prefix=on;
set global innodb_file_format=Barracuda;
参考:
https://dev.mysql.com/doc/refman/5.7/en/innodb-file-format.html (InnoDB文件格式)
https://dev.mysql.com/doc/refman/5.7/en/innodb-row-format.html#innodb-row-format-dynamic(InnoDB行格式)
https://www.cnblogs.com/kerrycode/p/9680881.html
https://blog.51cto.com/lee90/2153273
https://www.cnblogs.com/billyxp/p/3342969.html