mysql 查詢表儲存空間占用

2021-10-09 15:54:25 字數 1025 閱讀 9100

使用 schema 資料庫

mysql> use information_schema;
字段

說明table_schema

資料庫名

table_name

表名engine

所使用的儲存引擎

tables_rows

記錄數data_length

資料大小

index_length

索引大小

查詢資料庫總占用空間

mysql> select concat(round(sum(data_length/1024/1024), 2),'mb') as data_size from tables
查詢指定資料庫占用空間

mysql> select concat(round(sum(data_length/1024/1024), 2),'mb') as data_size 

from tables

where table_schema='db_name';

查詢指定表占用空間

mysql> select concat(round(sum(data_length/1024/1024),2),'mb') as 	

data_size

from tables

where table_schema='db_name' and table_name='tb_name';

mysql> select table_name, concat(round(sum(data_length/1024/1024),2),'mb') as 		

data_size

from tables

where table_schema='db_name'

group by table_name;

把data_length改為index_length就是查詢索引占用的空間了。

mysql和oracle查詢表占用空間

mysql 需要先進入information schema select table schema as 資料庫 table name as 表名 table rows as 記錄數 truncate data length 1024 1024,2 as 資料容量 mb truncate index...

MySql 表空間查詢

show variableslike datadir 查所有資料庫占用空間大小 select table schema,concat truncate sum data length 1024 1024,2 mb as data size,concat truncate sum index leng...

ORACLE查詢每個表占用空間大小

select select sum bytes from dba segments where owner testbar and segment type table and segment name table name from user tables 錯誤的,對於oracle而言,雙引號 要...