查询mysql数据库的占用大小。

1、 查看所有数据库的 占用

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;

2、 查看指定数据库中,每个表的占用

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 = 'database_name' 
GROUP BY
	TABLE_NAME 
ORDER BY
	data_length DESC;

2、 logs

show binary logs; 
posted @ 2021-03-19 11:09  做个笔记  阅读(126)  评论(0编辑  收藏  举报