如何查看MySQL单个数据库或者表的大小

Posted 石头儿

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何查看MySQL单个数据库或者表的大小相关的知识,希望对你有一定的参考价值。

总体来说,这些信息存在于information_schema数据库的TABLES表中

mysql> desc information_schema.TABLES;
+-----------------+---------------------+------+-----+---------+-------+
| Field           | Type                | Null | Key | Default | Extra |
+-----------------+---------------------+------+-----+---------+-------+
| TABLE_CATALOG   | varchar(512)        | NO   |     |         |       |
| TABLE_SCHEMA    | varchar(64)         | NO   |     |         |       |
| TABLE_NAME      | varchar(64)         | NO   |     |         |       |
| TABLE_TYPE      | varchar(64)         | NO   |     |         |       |
| ENGINE          | varchar(64)         | YES  |     | NULL    |       |
| VERSION         | bigint(21) unsigned | YES  |     | NULL    |       |
| ROW_FORMAT      | varchar(10)         | YES  |     | NULL    |       |
| TABLE_ROWS      | bigint(21) unsigned | YES  |     | NULL    |       |
| AVG_ROW_LENGTH  | bigint(21) unsigned | YES  |     | NULL    |       |
| DATA_LENGTH     | bigint(21) unsigned | YES  |     | NULL    |       |
| MAX_DATA_LENGTH | bigint(21) unsigned | YES  |     | NULL    |       |
| INDEX_LENGTH    | bigint(21) unsigned | YES  |     | NULL    |       |
| DATA_FREE       | bigint(21) unsigned | YES  |     | NULL    |       |
| AUTO_INCREMENT  | bigint(21) unsigned | YES  |     | NULL    |       |
| CREATE_TIME     | datetime            | YES  |     | NULL    |       |
| UPDATE_TIME     | datetime            | YES  |     | NULL    |       |
| CHECK_TIME      | datetime            | YES  |     | NULL    |       |
| TABLE_COLLATION | varchar(32)         | YES  |     | NULL    |       |
| CHECKSUM        | bigint(21) unsigned | YES  |     | NULL    |       |
| CREATE_OPTIONS  | varchar(255)        | YES  |     | NULL    |       |
| TABLE_COMMENT   | varchar(2048)       | NO   |     |         |       |
+-----------------+---------------------+------+-----+---------+-------+

# check database size

SELECT table_schema                                        "DB Name",     Round(Sum(data_length + index_length) / 1024 / 1024 / 1024, 1) "DB Size in GB"  FROM   information_schema.tables  GROUP  BY table_schema;

# check table size

SELECT table_schema as `Database`, table_name AS `Table`, round(((data_length + index_length) / 1024 / 1024 / 1024), 2) `Size in GB` FROM information_schema.TABLES where table_schema = ‘purge_qms‘ ORDER BY (data_length + index_length) DESC ;

以上是关于如何查看MySQL单个数据库或者表的大小的主要内容,如果未能解决你的问题,请参考以下文章

请问一下mysql是否限制了单个表的容量,能改吗

如何查看mysql数据库中各个表的大小

Oracle怎么查看表的大小?

mysql数据字典代码

如何查看SQL2000数据库中所有表的数据量大小

查看mysql库和表的大小(空间)