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

xwbd5t1u  于 2024-01-05  发布在  Mysql
关注(0)|答案(7)|浏览(172)

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

8e2ybdfx

8e2ybdfx1#

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

字符串
Source
这是我的:

  1. USE databasename;
  2. SHOW TABLES;
  3. SELECT FOUND_ROWS();

wb1gzix0

wb1gzix02#

如果您想计算所有数据库的数量以及摘要,请尝试以下操作:

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

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

  1. mysql> SELECT IFNULL(table_schema,'Total') "Database",TableCount
  2. -> FROM (SELECT COUNT(1) TableCount,table_schema
  3. -> FROM information_schema.tables
  4. -> WHERE table_schema NOT IN ('information_schema','mysql')
  5. -> GROUP BY table_schema WITH ROLLUP) A;
  6. +--------------------+------------+
  7. | Database | TableCount |
  8. +--------------------+------------+
  9. | performance_schema | 17 |
  10. | Total | 17 |
  11. +--------------------+------------+
  12. 2 rows in set (0.29 sec)


给予一个尝试!

展开查看全部
23c0lvtd

23c0lvtd3#

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

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

字符串

w8biq8rn

w8biq8rn4#

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

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

字符串

yv5phkfx

yv5phkfx5#

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

  1. SELECT
  2. COUNT(*)
  3. FROM
  4. `information_schema`.`tables`
  5. WHERE
  6. `table_schema` = 'my_database_name'
  7. ;

字符串

cl25kdpy

cl25kdpy6#

命令行:

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

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

wecizke3

wecizke37#

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

相关问题