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

  • 相关阅读:
    Python的网络编程 Socket编程
    Python之数据库模块安装 MySQLdb
    Python的内置函数
    Servlet及Tomcat介绍
    xml解析
    JDBC基础
    反射练习
    lambda和匿名内部类
    Object.wait()实现生产者消费者模式
    synchronized、lock及线程安全集合
  • 原文地址:https://www.cnblogs.com/debmzhang/p/4447313.html
Copyright © 2011-2022 走看看