本文章来给大家介绍一些常用的MySQL查看数据库、表的占用空间大小sql命令吧,希望此教程对各位同学会有所帮助.
•查看各库的大小,代码如下:
SELECT SUM(DATA_LENGTH)+SUM(INDEX_LENGTH) FROM information_schema.tables WHERE TABLE_SCHEMA='database_name';
结果是以字节为单位,除1024为K,除1048576为M.
•查看各表的大小,代码如下:
SELECT TABLE_NAME,DATA_LENGTH+INDEX_LENGTH,TABLE_ROWS FROM information_schema.tables WHERE TABLE_SCHEMA='database_name' AND TABLE_NAME='table_name';
•查看表的最后修改时间,代码如下:
sELECT TABLE_NAME,UPDATE_TIME FROM information_schema.tables where TABLE_SCHEMA='database_name';
LOG
information_schema 库的 TABLES 表,主要字段分别是:
TABLE_SCHEMA:数据库名
TABLE_NAME:表名
ENGINE:所使用的存储引擎
TABLES_ROWS:记录数
DATA_LENGTH:数据大小
INDEX_LENGTH:索引大小
自己应用的一个实例,代码如下:
- //先进去MySQL自带管理库:information_schema
- //自己的数据库:dbwww58com_kuchecarlib
- //自己的表:t_carmodelparamvalue
- mysql>useinformation_schema;
- Databasechanged
- mysql>selectdata_length,index_length
- ->fromtableswhere
- ->table_schema='dbwww58com_kuchecarlib'
- ->andtable_name='t_carmodelparamvalue';
- +-------------+--------------+
- |data_length|index_length|
- +-------------+--------------+
- |166379520|235782144|
- +-------------+--------------+
- 1rowinset(0.02sec)
- mysql>selectconcat(round(sum(data_length/1024/1024),2),'MB')asdata_length_MB,
- ->concat(round(sum(index_length/1024/1024),2),'MB')asindex_length_MB
- ->fromtableswhere
- ->table_schema='dbwww58com_kuchecarlib'
- ->andtable_name='t_carmodelparamvalue';
- +----------------+-----------------+
- |data_length_MB|index_length_MB|
- +----------------+-----------------+
- |158.67MB|224.86MB|
- +----------------+-----------------+
- 1rowinset(0.03sec)//phpfensi.com