mysql查看表大小排行

前言

备份的时候发现一些数据库挺大的,但是表很多,一个个去看不合适,所以用sql语句查一下

查看库大小排行
1
2
3
4
5
6
7
8
9
10
SELECT 
table_schema AS `Database`,
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS `Size (MB)`
FROM
information_schema.tables
GROUP BY
table_schema
ORDER BY
`Size (MB)` DESC;

查看表大小排行
1
2
3
4
5
6
7
8
9
10
SELECT
table_name AS `Table`,
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS `Size (MB)`
FROM
information_schema.tables
WHERE
table_schema = 'psi'
ORDER BY
`Size (MB)` DESC;

注意表排行的话,需要修改 table_schema 后面的值为你的数据库名称