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

被折叠的 条评论
为什么被折叠?



