db / 未分类 · 2012年5月15日

MySQL 查看表大小的几种方法

2种方法:
1:mysql命令行:
说明:
information_schema.TABLES.TABLE_SCHEMA = ‘ming’ and information_schema.TABLES.TABLE_NAME = ‘test’
信息存储在information_schema.TABLES这个表中,TABLE_SCHEMA 对应数据库名,TABLE_NAME 对应表名。
# 总大小 = DATA_LENGTH + INDEX_LENGTH
[root@localhost ~]# mysql -e "select * from information_schema.TABLES where information_schema.TABLES.TABLE_SCHEMA = 'wordpress' and information_schema.TABLES.TABLE_NAME = 'wp_posts' G"
*************************** 1. row ***************************
TABLE_CATALOG: NULL
TABLE_SCHEMA: ming
TABLE_NAME: test
TABLE_TYPE: BASE TABLE
ENGINE: MyISAM
VERSION: 10
ROW_FORMAT: Fixed
TABLE_ROWS: 406600
AVG_ROW_LENGTH: 117
DATA_LENGTH: 47572200
MAX_DATA_LENGTH: 32932572275146751
INDEX_LENGTH: 4174848
DATA_FREE: 0
AUTO_INCREMENT: 614609
CREATE_TIME: 2011-01-07 21:45:55
UPDATE_TIME: 2011-01-09 14:20:17
CHECK_TIME: NULL
TABLE_COLLATION: latin1_swedish_ci
CHECKSUM: NULL
CREATE_OPTIONS:
TABLE_COMMENT:
[root@localhost ~]#
2:直接查看数据文件
[root@localhost ~]# ls -l /opt/mysql/var/game/
总用量 50560
-rw-rw—- 1 mysql mysql 8706 1月 7 21:45 test.frm
-rw-rw—- 1 mysql mysql 47522124 1月 9 14:19 test.MYD
-rw-rw—- 1 mysql mysql 4170752 1月 9 14:19 test.MYI
-rw-rw—- 1 mysql mysql 65 1月 7 21:45 db.opt
[root@localhost ~]#
文件对应关系
test.MYD => DATA_LENGTH
test.MYI => INDEX_LENGTH
from hi.baidu.com