ITPub博客

首页 > IT职业 > IT职场 > MySQL数据和索引占用空间查询

MySQL数据和索引占用空间查询

IT职场 作者:flbwhx 时间:2021-09-09 10:47:06 0 删除 编辑

MySQL数据和索引占用空间查询

查询所有数据库占用磁盘空间大小的SQL语句

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
	sum( data_length ) DESC;

查询单个库中所有表磁盘占用大小的SQL语句

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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/933/viewspace-2826124/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    92
  • 访问量
    671