未知 table 'table_name' information_schema
Unknown table 'table_name' in information_schema
我想从每个具有 table_schema='foo'
(数据库名称)的 table show index
。
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
中的 table。如何重写查询以将 'table_name'
视为 information_schema.tables
中的列?
你的做法是错误的,你在编造不存在的语法。
我建议您获取索引的方式是阅读 INFORMATION_SCHEMA.STATISTICS
table,而不是 TABLES
table.
以下查询与 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';
您可能认为应该有一个名为 "INDEXES" 的 I_S table,但实际上索引对象的系统 table 被命名为 "STATISTICS"。去图吧。
我想从每个具有 table_schema='foo'
(数据库名称)的 table show index
。
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
中的 table。如何重写查询以将 'table_name'
视为 information_schema.tables
中的列?
你的做法是错误的,你在编造不存在的语法。
我建议您获取索引的方式是阅读 INFORMATION_SCHEMA.STATISTICS
table,而不是 TABLES
table.
以下查询与 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';
您可能认为应该有一个名为 "INDEXES" 的 I_S table,但实际上索引对象的系统 table 被命名为 "STATISTICS"。去图吧。