Answers:
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbName';
这是我的:
USE databasename;
SHOW TABLES;
SELECT FOUND_ROWS();
AND table_type = 'BASE TABLE'
use databasename;
命令的注释。如果数据库确实很大,该命令将需要很长的等待时间才能执行。在这种情况下,应使用选项-A(即:)完成登录mysql -uroot -p -A
,该命令将快速运行。
如果您想计算所有数据库以及摘要,请尝试以下操作:
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)
试试看 !!!
FROM
子句中使用子查询?为什么不只是SELECT IFNULL(table_schema, 'Total') Database, COUNT(*) TableCount FROM information_schema.tables WHERE table_schema NOT IN ('information_schema','mysql') GROUP BY table_schema WITH ROLLUP
呢?
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 WHERE table_schema = 'database_name';
从命令行:
mysql -uroot -proot -e "select count(*) from
information_schema.tables where table_schema = 'database_name';"
在上面的示例中,root是username和password,托管在localhost上。
希望这会有所帮助,并且仅返回数据库中的表数
Use database;
SELECT COUNT(*) FROM sys.tables;
sys.tables
中不存在mysql
FOUND_ROWS()
的表数大于使用第一种方法时返回的表数。