MySQL 数据库中的非空表列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4746201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:23:32  来源:igfitidea点击:

List of non-empty tables in MySQL database

mysqlsql

提问by ajreal

Can I get MySQL to return all non-empty tables in a database? Much like "SHOW TABLES" but only those that are not empty.

我可以让 MySQL 返回数据库中的所有非空表吗?很像“SHOW TABLES”,但只有那些不为空的。

回答by ajreal

'information_schema' should be holding the relevant details. You can try

'information_schema' 应该保存相关的细节。你可以试试

SELECT table_type,
       table_name
FROM information_schema.tables
WHERE table_rows >= 1;

to select from a selective database. You can also filter by TABLE_SCHEMA:

从选择性数据库中进行选择。您还可以按TABLE_SCHEMA以下条件过滤:

SELECT table_schema,
       table_type,
       table_name 
FROM information_schema.tables
WHERE table_rows >= 1
  AND TABLE_SCHEMA=?

回答by 3Gee

The accepted answer never worked for me, information_schematable_rowshave some very weird values.

接受的答案对我不起作用information_schema table_rows有一些非常奇怪的值。

This worked like a charm:

这就像一个魅力:

SHOW TABLE STATUS WHERE Rows > 0;

Docs for SHOW TABLE STATUS

SHOW TABLE STATUS 文档

回答by Yasen Zhelev

Use database 'information_schema' and run

使用数据库“information_schema”并运行

SELECT * FROM `TABLES` WHERE `TABLE_ROWS` > 0 

this will give you all non-empty tables in the server for a certain database run

这将为您提供服务器中某个数据库运行的所有非空表

SELECT * FROM `TABLES` WHERE `TABLE_ROWS` > 0  AND `TABLE_SCHEMA` = 'database_name'

回答by timpng1

You can run this query via phpMyAdmin:

您可以通过 phpMyAdmin 运行此查询:

SELECT * 
FROM  `information_schema`.`TABLES` 
WHERE  `TABLE_ROWS` > 0

will return a list of non-empty tables

将返回非空表的列表