mysql show table status 的替代方案:获得更多更具体的表信息

本文详细介绍了如何使用information_schema数据库来替代MySQL的showtablestatus语句,实现更灵活的数据表信息查询,包括按数据量排序、指定数据库、查找非InnoDB引擎的表等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mysql提供的show table status like ‘%xxx’可以方便的查看某些表的信息,但是使用这个语句没法对结果集进行排序,不如我想看数据库中那个表中的数据量最大就办不到了?

其实可以通过访问information_schema数据库获得show table status的相关信息

比如:

SELECT * FROM information_schema.tables WHERE table_schema = DATABASE();

获得按数据量排序的信息:

SELECT table_name,ENGINE,VERSION,ROW_FORMAT,table_rows,AVG_ROW_LENGTH,
Data_length,Max_data_length,Index_length,Data_free,AUTO_INCREMENT,
Create_time,Update_time,Check_time,table_collation,CHECKSUM,
Create_options,table_comment FROM information_schema.TABLES
WHERE table_schema = DATABASE()
ORDER BY table_rows DESC

也可以指定数据库:

SELECT table_name,Engine,Version,Row_format,table_rows,Avg_row_length,
Data_length,Max_data_length,Index_length,Data_free,Auto_increment,
Create_time,Update_time,Check_time,table_collation,Checksum,
Create_options,table_comment FROM information_schema.tables
WHERE table_schema = 'yourdb';

还可以方便的查询到那些表的引擎不是InnoDB,如下sql语句:

SELECT table_name,Engine,Version,Row_format,table_rows,Avg_row_length,
Data_length,Max_data_length,Index_length,Data_free,Auto_increment,
Create_time,Update_time,Check_time,table_collation,Checksum,
Create_options,table_comment FROM information_schema.tables
WHERE table_schema = 'yourdb' and Engine != 'InnoDB'

原文地址:http://outofmemory.cn/code-snippet/2411/mysql-show-table-status-tidai-scheme-get-gengduo-geng-juti-table-information


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值