檢視MYSQL資料庫的佔用空間
阿新 • • 發佈:2018-11-09
如果想知道mysql 資料庫中的每個表佔用的空間、表記錄的行數的話,可以開啟mysql的information_schema資料庫。在該庫中有一個tables表,這個表主要欄位分別是:
table_schema:資料庫名
table_name:表名
engine:所使用的儲存引擎
table_rows:記錄數
data_length:資料大小
index_length:索引大小
1、檢視指定資料庫例項的大小,比如資料庫zabbix2
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| monitor |
| mysql |
| test |
| wikidb |
| zabbix2 |
+--------------------+
6 rows in set (0.00 sec)
mysql> use information_schema;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select sum(data_length/1024/1024) as data from tables where table_schema='ZABBIX2';
+----------------+
| data |
+----------------+
| 57459.96875000 |
+----------------+
1 row in set (2.00 sec)
mysql> select round(sum(data_length/1024/1024),2) as data from tables where table_schema='ZABBIX2';
+----------+
| data |
+----------+
| 57462.97 |
+----------+
1 row in set (1.69 sec)
mysql> select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables where table_schema='ZABBIX2';
+------------+
| data |
+------------+
| 57463.97mb |
+------------+
1 row in set (1.46 sec)
concat 連線函式 返回結果為連線引數產生的字串。如有任何一個引數為NULL ,則返回值為 NULL。
2、檢視指定資料庫的表的大小,如資料庫 zabbix2中的history_log表
mysql> select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables
-> where table_schema='ZABBIX2' and table_name='history_log';
+--------+
| data |
+--------+
| 3.52mb |
+--------+
1 row in set (0.07 sec)
3、檢視所有資料的大小
select concat(round(sum(data_length/1024/1024)2),'MB') as data from tables;
mysql> select sum(data_length/1024/1024) as data from tables;
+----------------+
| data |
+----------------+
| 57493.09162331 |
+----------------+
1 row in set (5.18 sec)
table_schema:資料庫名
table_name:表名
engine:所使用的儲存引擎
table_rows:記錄數
data_length:資料大小
index_length:索引大小
1、檢視指定資料庫例項的大小,比如資料庫zabbix2
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| monitor |
| mysql |
| test |
| wikidb |
| zabbix2 |
+--------------------+
6 rows in set (0.00 sec)
mysql> use information_schema;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select sum(data_length/1024/1024) as data from tables where table_schema='ZABBIX2';
+----------------+
| data |
+----------------+
| 57459.96875000 |
+----------------+
1 row in set (2.00 sec)
mysql> select round(sum(data_length/1024/1024),2) as data from tables where table_schema='ZABBIX2';
+----------+
| data |
+----------+
| 57462.97 |
+----------+
1 row in set (1.69 sec)
mysql> select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables where table_schema='ZABBIX2';
+------------+
| data |
+------------+
| 57463.97mb |
+------------+
1 row in set (1.46 sec)
concat 連線函式 返回結果為連線引數產生的字串。如有任何一個引數為NULL ,則返回值為 NULL。
2、檢視指定資料庫的表的大小,如資料庫 zabbix2中的history_log表
mysql> select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables
-> where table_schema='ZABBIX2' and table_name='history_log';
+--------+
| data |
+--------+
| 3.52mb |
+--------+
1 row in set (0.07 sec)
3、檢視所有資料的大小
select concat(round(sum(data_length/1024/1024)2),'MB') as data from tables;
mysql> select sum(data_length/1024/1024) as data from tables;
+----------------+
| data |
+----------------+
| 57493.09162331 |
+----------------+
1 row in set (5.18 sec)