有时候我们需要统计MySql数据库中那些表有数据,对于比较简单的表我们可以手工逐一查看,但是对于表比较多的库我们在逐个去查看的话就比较费时费力,而且不准确,所以我们可以通过简单的SQL查询语句来实现我们想要的结果,简单的统计哪些表有数据,SQL语句如下:
select TABLE_NAME from information_schema.tables where TABLE_SCHEMA='当前数据库' and table_rows>0;
Code language: SQL (Structured Query Language) (sql)
执行结果

如果我们想在查询有数据表的同时需要列出每张表中的数据量是多少可以执行以下SQL语句:
use information_schema; select table_name,table_rows from tables where TABLE_SCHEMA = '数据库名称' and table_rows>0 order by table_rows desc;
Code language: SQL (Structured Query Language) (sql)
执行结果如下:
