shengyayun 10 X 10
shengyayun:~/blog$ source "mysql表占用空间分析.sh"

shengyayun:~/blog$ printenv
CREATED_DATE = 2019-07-25
UPDATED_DATE = 2019-07-25
TAGS = mysql
CATEGORIES =

shengyayun:~/blog$ grep -lr $TAGS post
2017-08-15 mysql配置与运行状态的分析与优化
2019-07-25 mysql表占用空间分析
mysql表占用空间分析
1
2
3
4
5
6
7
8
9
10
11
12
13
14
SELECT 
table_schema, #库名
table_name, #表名
table_comment, #表注释
`engine`, #表引擎
ROUND(data_length / 1024 / 1024, 2) AS 'Data', #数据占用(MB)
ROUND(data_free / 1024 / 1024, 2) AS 'Free', #碎片占用(MB)
ROUND(index_length / 1024 / 1024, 2) AS 'Index', #索引占用(MB)
ROUND((data_length + data_free + index_length) / 1024 / 1024, 2) AS 'Total' #合计占用
FROM
information_schema.tables
WHERE
table_schema NOT IN ('mysql' , 'sys', 'information_schema', 'performance_schema')
ORDER BY data_length + data_free + index_length DESC;