mysql中information_schema.tables字段说明、mysql统计表大小sql

1、表结构为:

CREATE TEMPORARY TABLE `TABLES` (
  `TABLE_CATALOG` varchar(512) NOT NULL DEFAULT '',
  `TABLE_SCHEMA` varchar(64) NOT NULL DEFAULT '',
  `TABLE_NAME` varchar(64) NOT NULL DEFAULT '',
  `TABLE_TYPE` varchar(64) NOT NULL DEFAULT '',
  `ENGINE` varchar(64) DEFAULT NULL,
  `VERSION` bigint(21) unsigned DEFAULT NULL,
  `ROW_FORMAT` varchar(10) DEFAULT NULL,
  `TABLE_ROWS` bigint(21) unsigned DEFAULT NULL,
  `AVG_ROW_LENGTH` bigint(21) unsigned DEFAULT NULL,
  `DATA_LENGTH` bigint(21) unsigned DEFAULT NULL,
  `MAX_DATA_LENGTH` bigint(21) unsigned DEFAULT NULL,
  `INDEX_LENGTH` bigint(21) unsigned DEFAULT NULL,
  `DATA_FREE` bigint(21) unsigned DEFAULT NULL,
  `AUTO_INCREMENT` bigint(21) unsigned DEFAULT NULL,
  `CREATE_TIME` datetime DEFAULT NULL,
  `UPDATE_TIME` datetime DEFAULT NULL,
  `CHECK_TIME` datetime DEFAULT NULL,
  `TABLE_COLLATION` varchar(32) DEFAULT NULL,
  `CHECKSUM` bigint(21) unsigned DEFAULT NULL,
  `CREATE_OPTIONS` varchar(255) DEFAULT NULL,
  `TABLE_COMMENT` varchar(2048) NOT NULL DEFAULT ''
) ENGINE=MEMORY DEFAULT CHARSET=utf8;

2、表字段说明:

字段含义
table_catalog数据表登记目录
table_schema数据表所属的数据库名
table_name表名称
table_type表类型[system view base table]
engine使用的数据库引擎[MyISAM、CSV、InnoDB]
version版本,默认值10
row_format行格式[Compact、Dynamic、Fixed]
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表的注释、备注

3、统计每个表的总行数,数据大小,索引大小和总大小

select CONCAT_WS('.',table_schema,table_name) '库表', table_schema,table_name
,table_rows '总行数'
,concat(truncate(sum(data_length)/1024/1024/1024,2),'G') as data_length_G   -- 数据大小
,concat(truncate(sum(index_length)/1024/1024/1024,2),'G') as index_length_G		-- 索引大小
,concat( truncate(SUM(data_length)+SUM(index_length),2)/1024/1024/1024,'G' ) as all_length_G -- 总大小
,SUM(data_length)+SUM(index_length) as all_length -- 总大小
from information_schema.tables 
group by table_name
-- HAVING all_length > 20000000000
order by all_length desc;

select CONCAT_WS('.',table_schema,table_name) '库表', table_schema,table_name
,table_rows '总行数'
,concat(truncate(sum(data_length)/1024/1024/1024,2),'G') as data_length_G   -- 数据大小
,concat(truncate(sum(index_length)/1024/1024/1024,2),'G') as index_length_G		-- 索引大小
,concat( truncate(SUM(data_length)+SUM(index_length),2)/1024/1024/1024,'G' ) as all_length_G -- 总大小
,SUM(data_length)+SUM(index_length) as all_length -- 总大小
from information_schema.tables
WHERE table_schema != 'information_schema'
group by table_name
order by table_schema,all_length desc;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值