•查看各庫的大小
代碼如下 復制代碼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> use information_schema;
Database changed
mysql> select data_length,index_length
-> from tables where
-> table_schema='dbwww58com_kuchecarlib'
-> and table_name = 't_carmodelparamvalue';
+-------------+--------------+
| data_length | index_length |
+-------------+--------------+
| 166379520 | 235782144 |
+-------------+--------------+
1 row in set (0.02 sec)
mysql> select concat(round(sum(data_length/1024/1024),2),'MB') as data_length_MB,
-> concat(round(sum(index_length/1024/1024),2),'MB') as index_length_MB
-> from tables where
-> table_schema='dbwww58com_kuchecarlib'
-> and table_name = 't_carmodelparamvalue';
+----------------+-----------------+
| data_length_MB | index_length_MB |
+----------------+-----------------+
| 158.67MB | 224.86MB |
+----------------+-----------------+
1 row in set (0.03 sec)