蛮荆

MySQL 运维 SQL 备忘

2019-03-16

查询 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;

查询 MySQL 数据库里面的单个数据库占用大小

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 = '数据库名 ';

查询 MySQL 数据库里面的单个数据库所有表各自占用大小

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 = '数据库名 '
GROUP BY TABLE_NAME
ORDER BY data_length DESC ;

查询 MySQL 数据库里面的单个数据库指定表占用大小

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_NAME = '表名';

转载申请

本作品采用 知识共享署名 4.0 国际许可协议 进行许可,转载时请注明原文链接,图片在使用时请保留全部内容,商业转载请联系作者获得授权。