大家好,我使用的数据库是mysql, 版本号5.7.11. 在新增一个表时报“Specified key was too long; max key length is 1000 bytes
”的错误,网络上查找的方法大概是两种,一种是修改表的默认字符集,一种是修改定义表的长度。我现在奇怪的是,这个表定义是哪一个地方出错了?原因是什么?现摘抄表的定义和错误信息如下,请大家帮助看下是什么原因。谢谢! CREATE TABLE graph_local (
    id mediumint(8) unsigned NOT NULL auto_increment,
    graph_template_id mediumint(8) unsigned NOT NULL default '0',
    host_id mediumint(8) unsigned NOT NULL default '0',
    snmp_query_id mediumint(8) NOT NULL default '0',
    snmp_index varchar(255) NOT NULL default '',
    PRIMARY KEY  (id),
    KEY host_id (host_id),
    KEY graph_template_id (graph_template_id),
    KEY snmp_query_id (snmp_query_id),
    KEY snmp_index (snmp_index)
  ) ENGINE=MyISAM COMMENT='Creates a relationship for each item in a custom graph.';
 
[SQL]  CREATE TABLE graph_local (
    id mediumint(8) unsigned NOT NULL auto_increment,
    graph_template_id mediumint(8) unsigned NOT NULL default '0',
    host_id mediumint(8) unsigned NOT NULL default '0',
    snmp_query_id mediumint(8) NOT NULL default '0',
    snmp_index varchar(255) NOT NULL default '',
    PRIMARY KEY  (id),
    KEY host_id (host_id),
    KEY graph_template_id (graph_template_id),
    KEY snmp_query_id (snmp_query_id),
    KEY snmp_index (snmp_index)
  ) ENGINE=MyISAM COMMENT='Creates a relationship for each item in a custom graph.';
[Err] 1071 - Specified key was too long; max key length is 1000 bytes

解决方案 »

  1.   

    这是网上找的一个解决办法,链接如下:http://www.oschina.net/question/87533_10510
    引用其中的答案可以解决,摘抄如下:
    刚解决完类似的问题,整理一下思路.
    1.DB engine 是MyIsAm
    2.字符集是 utf8 ,1个utf8=3bytes
    3.最后就是 (100+255)*3>1000 所以报错解决方案很多 ,修改DB engine 至 innodb,或者是更改字符集,或者是减小字段长度 皆可.
    :)
      

  2.   

    最后就是 (100+255)*3>1000 所以报错
    表定义只有一个snmp_index 是varchar255没有看到另外的100是在哪里?
      

  3.   

    谢谢版主的回复。上面引用别的帖子里的回复思路,graph_local这个表我是不明白为啥会报这个错误,按这样算也没超过1000.
      

  4.   

       按下贴中的方法检查字符集设置。并贴出以供分析。
       
       http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx