日常工作中查询mysql的Data size是最常用的查询,下面分享以下几个常用的使用方法
select table_schema as database_name, table_name, round(sum((data_length + index_length)) / power(1024, 2), 2) as used_mb, round(sum((data_length + index_length + data_free)) / power(1024, 2), 2) as allocated_mbfrom information_schema.tableswhere table_schema = 'your database name' -- put your database name here and table_type = 'BASE TABLE'group by table_schema, table_nameorder by used_mb desc;说明:
select table_schema as database_name, table_name, round(1.0*data_length/1024/1024, 2) as data_size, round(index_length/1024/1024, 2) as index_size, round((data_length + index_length)/1024/1024, 2) as total_sizefrom information_schema.tableswhere table_schema not in('information_schema', 'mysql', 'sys', 'performance_schema') -- and table_schema = 'your database name'order by total_size desc;说明:
select database_name, index_name, (1.0*stat_value*@@innodb_page_size/1024/1024) as index_size, table_namefrom mysql.innodb_index_statswhere stat_name = 'size' and index_name not in ('PRIMARY', 'GEN_CLUST_INDEX') -- and database_name = 'put your database name here'order by index_size desc;说明:
select table_schema as database_name, table_name, round( (data_length + index_length) / 1024 / 1024, 2) as total_size, round( (data_length) / 1024 / 1024, 2) as data_size, round( (index_length) / 1024 / 1024, 2) as index_sizefrom information_schema.tableswhere table_schema not in ('information_schema', 'mysql', 'performance_schema' ,'sys') and table_type = 'BASE TABLE' -- and table_schema = 'your database name'order by total_size desclimit 10;说明:
后面会分享更多精彩内容,感兴趣的朋友可以关注下!
| 留言与评论(共有 0 条评论) “” |