单库容量
SELECT
table_name AS 'Table Name',
table_rows AS 'Number of Rows',
ROUND((data_length + index_length) / 1024 / 1024, 2) AS 'Total Size (MB)',
ROUND(data_length / 1024 / 1024, 2) AS 'Data Size (MB)',
ROUND(index_length / 1024 / 1024, 2) AS 'Index Size (MB)'
FROM
information_schema.tables
WHERE
table_schema = 'xxxxx'
ORDER BY
data_length + index_length DESC;
所有库容量
SELECT
table_schema AS '数据库',
sum( table_rows ) AS '记录数',
sum(
TRUNCATE ( data_length / 1024 / 1024, 2 )) AS '数据容量(MB)',
sum(
TRUNCATE ( index_length / 1024 / 1024, 2 )) AS '索引容量(MB)'
FROM
information_schema.TABLES
GROUP BY
table_schema
ORDER BY
sum( data_length ) DESC,
sum( index_length ) DESC;
所有表容量
SELECT
table_schema AS '数据库',
table_name AS '表名',
table_rows AS '记录数',
ROUND((data_length + index_length) / 1024 / 1024, 2) AS 'Total Size (MB)',
ROUND(data_length / 1024 / 1024, 2) AS '数据容量 (MB)',
ROUND(index_length / 1024 / 1024, 2) AS '索引容量 (MB)'
FROM
information_schema.tables
WHERE
table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
ORDER BY
table_schema,
(data_length + index_length) DESC;
库清理
OPTIMIZE TABLE example_table;