用SQL命令檢視Mysql資料庫大小

lhrbest發表於2017-03-23
用SQL命令檢視Mysql資料庫大小

除了可以直接進入後臺檢視資料檔案大小,可以用SQL命令檢視Mysql資料庫大小

1、進入information_schema 資料庫(存放其他的資料庫的資訊的資料庫)
 mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cacti              |
| centreon           |
| centreon_status    |
| centreon_storage   |
| dumpfile           |
| mysql              |
| syslog             |
| test               |
+--------------------+
9 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>
mysql>
mysql> show tables;
+---------------------------------------+
| Tables_in_information_schema          |
+---------------------------------------+
| CHARACTER_SETS                        |
| COLLATIONS                            |
| COLLATION_CHARACTER_SET_APPLICABILITY |
| COLUMNS                               |
| COLUMN_PRIVILEGES                     |
| ENGINES                               |
| EVENTS                                |
| FILES                                 |
| GLOBAL_STATUS                         |
| GLOBAL_VARIABLES                      |
| KEY_COLUMN_USAGE                      |
| PARTITIONS                            |
| PLUGINS                               |
| PROCESSLIST                           |
| PROFILING                             |
| REFERENTIAL_CONSTRAINTS               |
| ROUTINES                              |
| SCHEMATA                              |
| SCHEMA_PRIVILEGES                     |
| SESSION_STATUS                        |
| SESSION_VARIABLES                     |
| STATISTICS                            |
| TABLES                                |
| TABLE_CONSTRAINTS                     |
| TABLE_PRIVILEGES                      |
| TRIGGERS                              |
| USER_PRIVILEGES                       |
| VIEWS                                 |
+---------------------------------------+
28 rows in set (0.00 sec)


2、查詢所有資料的大小:
mysql> select concat(round(sum(data_length/1024/1024/1024),2),'GB') as data from tables;
+----------+
| data     |
+----------+
| 110.86GB |
+----------+
1 row in set (1.25 sec)



3、檢視指定資料庫的大小:
mysql> select concat(round(sum(data_length/1024/1024/1024),2),'GB') as data from tables where table_schema='centreon_status';
+--------+
| data   |
+--------+
| 4.12GB |
+--------+
1 row in set (0.56 sec)




4、檢視指定資料庫的某個表的大小
比如檢視資料庫home中 members 表的大小
mysql> select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='centreon_status' and table_name='nagios_hosts';
+--------+
| data   |
+--------+
| 0.31MB |
+--------+
1 row in set (0.00 sec)

mysql>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-2135954/,如需轉載,請註明出處,否則將追究法律責任。

相關文章