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字符集,那索引还是建立不了。

  • 相关阅读:
    HTTP
    nginx反向代理和负载均衡
    keepalive
    lnmp
    DNS
    jumpserver跳板机
    博客已搬家到CSDN
    JAVA中关于上传图片到数据库和从数据库取出显示图片的问题
    checkbox的标签和全选中问题
    SOCKET
  • 原文地址:https://www.cnblogs.com/debmzhang/p/4447313.html
Copyright © 2011-2022 走看看