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

xwbd5t1u  于 11个月前  发布在  Mysql
关注(0)|答案(7)|浏览(99)

我的表的数量不断增加,有时我很好奇,想用一个快速的命令行查询来计算数据库中的表的数量。这可能吗?如果可能,查询是什么?

8e2ybdfx

8e2ybdfx1#

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

字符串
Source
这是我的:

USE databasename; 
SHOW TABLES; 
SELECT FOUND_ROWS();

wb1gzix0

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;

字符串
下面是一个示例运行:

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)


给予一个尝试!

23c0lvtd

23c0lvtd3#

如果你只是想得到没有视图的表的计数,你可以这样做:

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

字符串

w8biq8rn

w8biq8rn4#

这将给予你mysql中所有数据库的名称和表数

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

字符串

yv5phkfx

yv5phkfx5#

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

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

字符串

cl25kdpy

cl25kdpy6#

命令行:

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

字符串
在上面示例中,root是用户名和密码,托管在localhost上。

wecizke3

wecizke37#

mysql> show tables;
它将显示表的名称,然后显示表的计数。
source

相关问题