MariaDB是否允许255个字符的唯一索引? [英] Does MariaDB allow 255 character unique indexes?

查看:93
本文介绍了MariaDB是否允许255个字符的唯一索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我反复从10.0.29-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04收到此错误

I'm repeatedly getting this error from 10.0.29-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

第81行的错误1071(42000):指定的密钥太长;最大键 长度为767字节

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

目标行通常如下所示:

name VARCHAR(255) NOT NULL UNIQUE,

将其更改为VARCHAR(63)可使错误消失.这是MariaDB中的错误吗?

Changing it to a VARCHAR(63) makes the error go away. Is this a bug in MariaDB?

推荐答案

要变通解决此错误,请执行以下操作之一

To work around this error, do one of

解决方法:执行以下一项操作

Workaround: do one of

  • 升级到5.7.7(或更高版本)以获取3072个字节的限制,而不是767
  • VARCHAR上将255更改为191(假设您的值不太长)
  • ALTER .. CONVERT TO utf8-但这不允许表情符号和一些中文
  • 使用前缀"索引(不建议使用)
  • 重新配置(适用于5.6.3-5.7.6)(如下)
  • Upgrade to 5.7.7 (or later) for 3072 byte limit instead of 767
  • Change 255 to 191 on the VARCHAR (assuming your values are not too long)
  • ALTER .. CONVERT TO utf8 -- but this disallows Emoji and some Chinese
  • Use a "prefix" index (ill-advised)
  • Reconfigure (for 5.6.3 - 5.7.6) (below)

重新配置5.6.3或5.5.14:

Reconfiguring 5.6.3 or 5.5.14:

SET GLOBAL innodb_file_format=Barracuda;
SET GLOBAL innodb_file_per_table=1;
SET GLOBAL innodb_large_prefix=1;
logout & login (to get the global values);
ALTER TABLE tbl ROW_FORMAT=DYNAMIC;  (or COMPRESSED)

(版本号基于Oracle的MySQL; MariaDB版本号与此问题不同.)

(The version numbers are based on Oracle's MySQL; the MariaDB version numbers are different for this issue.)

这篇关于MariaDB是否允许255个字符的唯一索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆