如何使用mysql 命令列 檢視mysql表大小、資料大小、索引大小
阿新 • • 發佈:2019-01-21
select * from information_schema.TABLES
where information_schema.TABLES.TABLE_SCHEMA='databasename' and information_schema.TABLES.TABLE_NAME='tablename'\G
返回結果:
*************************** 1. row *************************** TABLE_CATALOG: def TABLE_SCHEMA: databasename TABLE_NAME: tablename TABLE_TYPE: BASE TABLE ENGINE: MyISAM VERSION: 10 ROW_FORMAT: Dynamic TABLE_ROWS: 6422930 AVG_ROW_LENGTH: 213 DATA_LENGTH: 1370884700 MAX_DATA_LENGTH: 281474976710655 INDEX_LENGTH: 412930048 DATA_FREE: 0 AUTO_INCREMENT: 6422931 CREATE_TIME: 2012-05-11 05:00:02 UPDATE_TIME: 2012-05-22 15:12:06 CHECK_TIME: 2012-05-11 09:58:52 TABLE_COLLATION: utf8_general_ci CHECKSUM: NULL CREATE_OPTIONS: TABLE_COMMENT: 'table comment' 1 row in set (0.00 sec)
其中:
information_schema.TABLES.TABLE_SCHEMA = ‘databasename’ and information_schema.TABLES.TABLE_NAME = ‘tablename’
資訊儲存在information_schema.TABLES這個表中,TABLE_SCHEMA 對應資料庫名,TABLE_NAME 對應表名。
# TABLE_ROWS 代表擁有的資料行數。
# 總大小 = DATA_LENGTH(資料大小) + INDEX_LENGTH(索引大小)
結果以位元組為單位,除1024為K,除1048576(=1024*1024)為M。