欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mysql查看数据库或表的占用磁盘空间

程序员文章站 2022-06-30 12:33:59
mysql查看数据库或表的占用磁盘空间查看全部库select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2),' MB') as data_size, concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size from information_schema.tables group by TABLE_SCHEMA order by data_lengt...

mysql查看数据库或表的占用磁盘空间

查看全部库

select TABLE_SCHEMA, 
concat(truncate(sum(data_length)/1024/1024,2),' MB') as data_size, 
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size 
from information_schema.tables group by TABLE_SCHEMA order by data_length desc;

单个库

select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,
concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,
concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables where TABLE_SCHEMA ='databasename';

单个库所有表

select TABLE_NAME, concat(truncate(data_length/1024/1024,2),' MB')as data_size, 
concat(truncate(index_length/1024/1024,2),' MB') as index_size 
from information_schema.tables where 
TABLE_SCHEMA = 'databasename' group by TABLE_NAME order by data_length desc;

注:sql语句中的databasename替换成自己要查的库名

或者通过磁盘统计大致查看:

mysql> select @@datadir;
+-----------------------+
| @@datadir             |
+-----------------------+
| /usr/local/mysql/var/ |
+-----------------------+
1 row in set (0.00 sec)
]#du -h /usr/local/mysql/var/ --max-depth=1

本文地址:https://blog.csdn.net/qq_41788609/article/details/107641212