查询数据库中表数量和数据量

时间:2025-03-22 08:34:13

一、切换到information_schema数据库

use information_schema;

二、查询数据库中所有表

# 查询该库表数量
select count(table_name) from TABLES where   TABLE_SCHEMA  = '库名';

# 查询该库中所有表名
select table_name from TABLES where   TABLE_SCHEMA  = '库名';

三、查询数据库数据量

# 查询数据库数据总行数
select sum(table_rows) from tables where table_schema = '库名';

# 查询数据库每张表的数据量
select table_name,table_rows from tables where table_schema = '库名' ORDER BY table_rows desc;