概述
当我们进入一个新环境,需要对数据库整体有个大致了解时,就需要dba去做个大概数据字典。
下面提供一个简单的数据字典统计sql,大家也可以将结果导到excel,然后结合excel的图形,就能大致了解整个数据库的概要。
实用sql
SELECTt1.table_schema,t1.table_name,`ENGINE`,table_rows,CAST( data_length / 1024.0 / 1024.0 AS DECIMAL ( 10, 2 ) ) `data_size(M)`,CAST( index_length / 1024.0 / 1024.0 AS DECIMAL ( 10, 2 ) ) `index_size(M)`,t2.ct col_count,t3.ct idx_count,create_time,table_comment FROMinformation_schema.TABLES t1LEFT JOIN -- 字段总数( SELECT table_name, COUNT( 1 ) ct FROM information_schema.COLUMNS GROUP BY table_name ) t2 ON t1.table_name = t2.table_nameLEFT JOIN -- 索引总数( SELECT table_name, COUNT( DISTINCT index_name ) ct FROM information_schema.STATISTICS GROUP BY table_name ) t3 ON t1.table_name = t3.table_name WHEREt1.table_schema NOT IN ( 'mysql', 'information_schema', 'performance_schema' ) ORDER BYt1.data_length DESC;
导出excel如下:
觉得有用的朋友多帮忙转发哦!后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注下~