查询来计算我在MySQL中拥有的表的数量

我正在增长我有的表的数量,我有时好奇,只是做一个快速的命令行查询来计算我的数据库中的表的数量。 那可能吗? 如果是这样,查询是什么?

SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbName'; 

资源

这是我的:

 USE databasename; SHOW TABLES; SELECT FOUND_ROWS(); 

如果你想要统计所有的数据库加上一个总结,请试试这个:

 SELECT IFNULL(table_schema,'Total') "Database",TableCount FROM (SELECT COUNT(1) TableCount,table_schema FROM information_schema.tables WHERE table_schema NOT IN ('information_schema','mysql') GROUP BY table_schema WITH ROLLUP) A; 

这是一个示例运行:

 mysql> SELECT IFNULL(table_schema,'Total') "Database",TableCount -> FROM (SELECT COUNT(1) TableCount,table_schema -> FROM information_schema.tables -> WHERE table_schema NOT IN ('information_schema','mysql') -> GROUP BY table_schema WITH ROLLUP) A; +--------------------+------------+ | Database | TableCount | +--------------------+------------+ | performance_schema | 17 | | Total | 17 | +--------------------+------------+ 2 rows in set (0.29 sec) 

试一试 !!!

 SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbo' and TABLE_TYPE='BASE TABLE' 

这会给你你所有数据库的名字和表的数量mysql

 SELECT TABLE_SCHEMA,COUNT(*) FROM information_schema.tables group by TABLE_SCHEMA; 
 SELECT COUNT(*) FROM information_schema.tables 

可能有多种方法来统计数据库的表。 我最喜欢的是这个:

 SELECT COUNT(*) FROM `information_schema`.`tables` WHERE `table_schema` = 'my_database_name' ; 

要计算表的数量,只需执行以下操作:

 USE your_db_name; -- set database SHOW TABLES; -- tables lists SELECT FOUND_ROWS(); -- number of tables 

有时候简单的事情会做这项工作。

 select name, count(*) from DBS, TBLS where DBS.DB_ID = TBLS.DB_ID group by NAME into outfile '/tmp/QueryOut1.csv' fields terminated by ',' lines terminated by '\n'; 
 SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'database_name'; 

从命令行:

 mysql -uroot -proot -e "select count(*) from information_schema.tables where table_schema = 'database_name';" 

在上面的例子中,root是用户名和密码,托pipe在本地主机上。

您可以使用下面的查询来查找数据库中表的总数。

 select count(*) from information_schema.tables 

希望这会有所帮助,并只返回数据库中的表的数量

 Use database; SELECT COUNT(*) FROM sys.tables;