查看整个数据库大小
SELECT sum(round(data_length / (1024 * 1024), 2) ) data_length,
sum(round(index_length / (1024 * 1024), 2) ) index_length,
sum(round(round(data_length + index_length) / (1024 * 1024), 2)
) total_size
FROM information_schema.TABLES;
查看每个表空间的大小
SELECT sum(round(data_length / (1024 * 1024), 2) ) data_length,
sum(round(index_length / (1024 * 1024), 2) ) index_length,
sum(round(round(data_length + index_length) / (1024 * 1024), 2)
) total_size
FROM information_schema.TABLES;
SELECT table_schema,
sum(round(data_length / (1024 * 1024), 2) ) data_length,
sum(round(index_length / (1024 * 1024), 2) ) index_length,
sum(round(round(data_length + index_length) / (1024 * 1024), 2)
) total_size
FROM information_schema.TABLES
group by table_schema;
SELECT table_schema,
sum(round(data_length / (1024 * 1024), 2) ) data_length,
sum(round(index_length / (1024 * 1024), 2) ) index_length,
sum(round(round(data_length + index_length) / (1024 * 1024), 2)
) total_size
FROM information_schema.TABLES
group by table_schema;
查看某个表空间的大小
SELECT concat(table_schema, '.', table_name) table_name,
concat(round(data_length / (1024 * 1024), 2), 'M') data_length,
concat(round(index_length / (1024 * 1024), 2), 'M') index_length,
concat(round(round(data_length + index_length) / (1024 * 1024), 2),
'M') total_size
FROM information_schema.TABLES
where table_schema='test'
ORDER BY data_length DESC;
查看所有表的大小
SELECT concat(table_schema, '.', table_name) table_name,
concat(round(data_length / (1024 * 1024), 2), 'M') data_length,
concat(round(index_length / (1024 * 1024), 2), 'M') index_length,
concat(round(round(data_length + index_length) / (1024 * 1024), 2),
'M') total_size
FROM information_schema.TABLES
where table_schema='test'
ORDER BY data_length DESC;
SELECT concat(table_schema, '.', table_name) table_name,
concat(round(data_length / (1024 * 1024), 2), 'M') data_length,
concat(round(index_length / (1024 * 1024), 2), 'M') index_length,
concat(round(round(data_length + index_length) / (1024 * 1024), 2),
'M') total_size
FROM information_schema.TABLES
ORDER BY data_length DESC;
查看某张表的大小
SELECT concat(table_schema, '.', table_name) table_name,
concat(round(data_length / (1024 * 1024), 2), 'M') data_length,
concat(round(index_length / (1024 * 1024), 2), 'M') index_length,
concat(round(round(data_length + index_length) / (1024 * 1024), 2),
'M') total_size
FROM information_schema.TABLES
ORDER BY data_length DESC;
select table_schema, table_name,TABLE_TYPE,ENGINE,TABLE_ROWS,
concat(round(data_length / (1024 * 1024), 2), 'M') data_length,
concat(round(index_length / (1024 * 1024), 2), 'M') index_length,
concat(round(round(data_length + index_length) / (1024 * 1024), 2),
'M') total_size
from information_schema.tables where table_name='user';
select table_schema, table_name,TABLE_TYPE,ENGINE,TABLE_ROWS,
concat(round(data_length / (1024 * 1024), 2), 'M') data_length,
concat(round(index_length / (1024 * 1024), 2), 'M') index_length,
concat(round(round(data_length + index_length) / (1024 * 1024), 2),
'M') total_size
from information_schema.tables where table_name='user';