计数 MySQL 个表总是 returns 零?
Counting MySQL tables always returns zero?
我肯定遗漏了一些非常明显的东西,但我有这个非常基本的 MySQL 查询:
SELECT count(*) from information_schema.tables WHERE table_schema == "my_table";
但是,此查询始终 returns 为零,即使存在 "my_table" 也是如此。我在这里错过了什么?
在 where 条件中使用单个 =
运算符。试试这个查询
SELECT count(*) from information_schema.tables WHERE table_schema = 'my_table';
阅读它了解更多信息Official Link
双==
就是问题所在。这不是 C/C++ :-)
在特定架构(数据库)中搜索 table。您必须在查询中提供 TABLE_SCHEMA
。
SELECT count(*) from information_schema.tables where table_name = 'my_table' and table_schema = 'database_name'
同时执行 SELECT * from information_schema.tables
以查看 table 保存的其他信息。
当我 运行 SELECT table_schema from information_schema.tables
时,它是 returns 数据库名称,而不是 table 名称。
我肯定遗漏了一些非常明显的东西,但我有这个非常基本的 MySQL 查询:
SELECT count(*) from information_schema.tables WHERE table_schema == "my_table";
但是,此查询始终 returns 为零,即使存在 "my_table" 也是如此。我在这里错过了什么?
在 where 条件中使用单个 =
运算符。试试这个查询
SELECT count(*) from information_schema.tables WHERE table_schema = 'my_table';
阅读它了解更多信息Official Link
双==
就是问题所在。这不是 C/C++ :-)
在特定架构(数据库)中搜索 table。您必须在查询中提供 TABLE_SCHEMA
。
SELECT count(*) from information_schema.tables where table_name = 'my_table' and table_schema = 'database_name'
同时执行 SELECT * from information_schema.tables
以查看 table 保存的其他信息。
当我 运行 SELECT table_schema from information_schema.tables
时,它是 returns 数据库名称,而不是 table 名称。