ITPub博客

首页 > 数据库 > MySQL > mysql查表空间大小的SQL语句

mysql查表空间大小的SQL语句

原创 MySQL 作者:chenfeng 时间:2016-03-01 20:54:54 0 删除 编辑
SQL语句如下:

select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,
concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,
concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables where TABLE_SCHEMA = 'databasename';

例如查mysql数据库表空间大小:
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db_shop            |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.52 sec)


mysql>
mysql> select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,
    -> concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,
    -> concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,
    -> concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
    -> from information_schema.tables where TABLE_SCHEMA = 'mysql';
+-----------+--------------------+-----------+------------+
| data_size | max_data_size      | data_free | index_size |
+-----------+--------------------+-----------+------------+
| 0.51MB    | 1938103992319.99MB | 0.00MB    | 0.09MB     |
+-----------+--------------------+-----------+------------+
1 row in set (1.49 sec)


mysql>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15498/viewspace-2021424/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
交流MySQL,MongoDB和Redis技术。 微信或QQ:410294

注册时间:2015-12-07

  • 博文量
    748
  • 访问量
    1774120