码迷,mamicode.com
首页 > 数据库 > 详细

查看数据库的大小

时间:2014-10-22 16:06:51      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:数据库   mysql   

1.查看数据库的大小


mysql> desc 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   |     |         |       |

+-----------------+---------------------+------+-----+---------+-------+

21 rows in set (0.02 sec)


mysql> select sum(DATA_LENGTH)+sum(INDEX_LENGTH) from tables where TABLE_SCHEMA=‘tpcc‘;

+------------------------------------+

| sum(DATA_LENGTH)+sum(INDEX_LENGTH) |

+------------------------------------+

|                        52817952768 |

+------------------------------------+

1 row in set (0.06 sec)


mysql> select (sum(DATA_LENGTH)+sum(INDEX_LENGTH))/1024/1024 from tables where TABLE_SCHEMA=‘tpcc‘;

+------------------------------------------------+

| (sum(DATA_LENGTH)+sum(INDEX_LENGTH))/1024/1024 |

+------------------------------------------------+

|                                 50605.17187500 |

+------------------------------------------------+

1 row in set (0.00 sec)


得到的单位是MB


mysql> select (sum(DATA_LENGTH)+sum(INDEX_LENGTH))/1024/1024/1024 from tables where TABLE_SCHEMA=‘tpcc‘;

+-----------------------------------------------------+

| (sum(DATA_LENGTH)+sum(INDEX_LENGTH))/1024/1024/1024 |

+-----------------------------------------------------+

|                                     49.419113159180 |

+-----------------------------------------------------+

1 row in set (0.00 sec)


得到的是GB


得到的结果是以字节为单位,除1024为K,除1048576为M。



计算数据库表的大小:


mysql> select table_schema,table_name,(data_length+index_length)/1024/1024/1024,table_rows from tables where table_schema=‘tpcc‘ and table_name=‘customer‘;

+--------------+------------+-------------------------------------------+------------+

| table_schema | table_name | (data_length+index_length)/1024/1024/1024 | table_rows |

+--------------+------------+-------------------------------------------+------------+

| tpcc         | customer   |                           16.292968750000 |   24633762 |

+--------------+------------+-------------------------------------------+------------+

1 row in set (0.00 sec)


#######################################################################################################################################################


计算表的数据大小和索引的大小:


mysql> select table_schema,table_name,index_length/1024/1024/1024,table_rows from tables where table_schema=‘tpcc‘ and table_name=‘customer‘; 

+--------------+------------+-----------------------------+------------+

| table_schema | table_name | index_length/1024/1024/1024 | table_rows |

+--------------+------------+-----------------------------+------------+

| tpcc         | customer   |              1.541992187500 |   25132578 |

+--------------+------------+-----------------------------+------------+

1 row in set (0.00 sec)


mysql> 

mysql> 

mysql> select table_schema,table_name,data_length/1024/1024/1024,table_rows from tables where table_schema=‘tpcc‘ and table_name=‘customer‘;

+--------------+------------+----------------------------+------------+

| table_schema | table_name | data_length/1024/1024/1024 | table_rows |

+--------------+------------+----------------------------+------------+

| tpcc         | customer   |            14.750976562500 |   25200169 |

+--------------+------------+----------------------------+------------+

1 row in set (0.00 sec)


mysql> 



mysql -e "use information_schema;select table_schema,table_name,data_length/1024/1024/1024,table_rows from tables where table_schema=‘tpcc‘ and table_name=‘customer‘;"


查看数据库的大小

标签:数据库   mysql   

原文地址:http://165084.blog.51cto.com/155084/1566681

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!