我的表的数量不断增加,有时我很好奇,想用一个快速的命令行查询来计算数据库中的表的数量。这可能吗?如果可能,查询是什么?
8e2ybdfx1#
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbName';
字符串Source这是我的:
USE databasename; SHOW TABLES; SELECT FOUND_ROWS();
USE databasename;
SHOW TABLES;
SELECT FOUND_ROWS();
型
wb1gzix02#
如果您想计算所有数据库的数量以及摘要,请尝试以下操作:
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;
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)
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)
型给予一个尝试!
23c0lvtd3#
如果你只是想得到没有视图的表的计数,你可以这样做:
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbo' and TABLE_TYPE='BASE TABLE'
字符串
w8biq8rn4#
这将给予你mysql中所有数据库的名称和表数
SELECT TABLE_SCHEMA,COUNT(*) FROM information_schema.tables group by TABLE_SCHEMA;
yv5phkfx5#
可能有多种方法来计算数据库的表数。我最喜欢的是:
SELECT COUNT(*)FROM `information_schema`.`tables`WHERE `table_schema` = 'my_database_name';
SELECT
COUNT(*)
FROM
`information_schema`.`tables`
WHERE
`table_schema` = 'my_database_name'
;
cl25kdpy6#
命令行:
mysql -uroot -proot -e "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是用户名和密码,托管在localhost上。
wecizke37#
mysql> show tables;它将显示表的名称,然后显示表的计数。source
7条答案
按热度按时间8e2ybdfx1#
字符串
Source
这是我的:
型
wb1gzix02#
如果您想计算所有数据库的数量以及摘要,请尝试以下操作:
字符串
下面是一个示例运行:
型
给予一个尝试!
23c0lvtd3#
如果你只是想得到没有视图的表的计数,你可以这样做:
字符串
w8biq8rn4#
这将给予你mysql中所有数据库的名称和表数
字符串
yv5phkfx5#
可能有多种方法来计算数据库的表数。我最喜欢的是:
字符串
cl25kdpy6#
命令行:
字符串
在上面示例中,root是用户名和密码,托管在localhost上。
wecizke37#
mysql> show tables;
它将显示表的名称,然后显示表的计数。
source