zoukankan      html  css  js  c++  java
  • warning:1071 (42000) Specified key was too long;max key length is 1000 bytes

    原因是mysql字段长度设置的太长了, 从而导致mysql在建立索引时,索引长度超过了mysql默认许可的长度

    默认 Innodb 允许长度为 767

    MyISAM 允许长度为 1000

    官方说明 如下:

    Prefix support and lengths of prefixes (where supported) are storage engine dependent. For example, a prefix can be up to 767 bytes long for InnoDB tables or 3072 bytes if the innodb_large_prefix option is enabled. For MyISAM tables, the prefix limit is 1000 bytes.

    转一份通俗易懂的 [以下内容转自 http://www.jb51.net/article/24499.htm ]

    建立索引时,数据库计算key的长度是累加所有Index用到的字段的char长度后再按下面比例乘起来不能超过限定的key长度1000: 
    latin1 = 1 byte = 1 character 
    uft8 = 3 byte = 1 character 
    gbk = 2 byte = 1 character 
    举例能看得更明白些,以GBK为例: 
    CREATE UNIQUE INDEX `unique_record` ON reports (`report_name`, `report_client`, `report_city`); 
    其中report_name varchar(200), report_client varchar(200), report_city varchar(200) 
    (200 + 200 +200) * 2 = 1200 > 1000,所有就会报1071错误,只要将report_city改为varchar(100)那么索引就能成功建立。 
    如果表是UTF8字符集,那索引还是建立不了。

  • 相关阅读:
    linux-who
    Linux开机禁用开启防火墙
    linux环境vnc安装
    NFS配置及开机自动挂载
    yum list失败
    镜像文件挂载及本地yum搭建
    weblogic在64位windows的设置
    linux操作系统语言更改
    Linux磁盘空间扩容(LVM)
    Nginx 拒接服务漏洞(CVE-2016-0747)整改
  • 原文地址:https://www.cnblogs.com/debmzhang/p/4447313.html
Copyright © 2011-2022 走看看