代码之家  ›  专栏  ›  技术社区  ›  onepiece

information_schema中的未知表“table_name”

  •  0
  • onepiece  · 技术社区  · 7 年前

    show index table_schema='foo' (数据库名称)。

    mysql> show index from table_name from information_schema.tables where table_schema='foo';
    ERROR 1109 (42S02): Unknown table 'table_name' in information_schema
    

    从错误中,我看到查询处理 'table_name' 作为一张桌子 information_schema .如何重写查询以处理 information_schema.tables ?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Bill Karwin    7 年前

    你的做法是错误的,你在编造不存在的语法。

    我建议您获取索引的方法是读取 INFORMATION_SCHEMA.STATISTICS 表,而不是 TABLES 桌子

    以下查询具有与相同的列: SHOW INDEXES :

    SELECT table_name AS `Table`, Non_unique, index_name AS Key_name,
      Seq_in_index, Column_name, Collation, Cardinality, Sub_part,
      Packed, Nullable, Index_type, Comment, Index_comment 
    FROM INFORMATION_SCHEMA.STATISTICS 
    WHERE table_schema = 'foo';
    

    您可能认为应该有一个名为“索引”的I_S表,但实际上索引对象的系统表名为“统计”。想想看吧