MySQL 运维 SQL 备忘
2019-03-16
DatabASe
MySQL
查询 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 = '表名';