实例:

查看某个库的大小

mysql>use information_schema;

mysql>select concat(round(sum(DATA_LENGTH+index_length)/1024/1024,2),'MB') as data_mb,concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data_mb,concat(round(sum(index_LENGTH/1024/1024),2),'MB') as index_mb from tables where table_schema='employees';      

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

| data_mb  | data_mb  | index_mb |

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

| 188.44MB | 134.25MB | 54.19MB  |

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

1 row in set (0.00 sec)

查看某个库的某个表的大小

select concat(round(sum(DATA_LENGTH+index_length)/1024/1024,2),'MB') as data_mb,concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data_mb,concat(round(sum(index_LENGTH/1024/1024),2),'MB') as index_mb from tables where table_schema='employees'and table_name='employees';

----------------------------------------------------------------------------------------------

concat 和round 函数说明

1.round 四余五入函数,如round(2.555)结果为3,round(2.555,2)表示以2位小数来四舍五入,如果为2.56.

可以在终端试一下啊.

select round(2.555,2) from dual;

2.concat

MySQL concat函数使用方法:

CONCAT(str1,str2,…)


返回结果为连接参数产生的字符串。如有任何一个参数为NULL ,则返回值为 NULL。


注意:

如果所有参数均为非二进制字符串,则结果为非二进制字符串。

如果自变量中含有任一二进制字符串,则结果为一个二进制字符串。

一个数字参数被转化为与之相等的二进制字符串格式;若要避免这种情况,可使用显式类型 cast, 例如:

SELECT CONCAT(CAST(int_col AS CHAR), char_col)


MySQL concat函数可以连接一个或者多个字符串,如


mysql> select concat('10');  

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

| concat('10') |  

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

| 10   |  

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

1 row in set (0.00 sec)  


mysql> select concat('11','22','33');  

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

| concat('11','22','33') |  

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

| 112233 |  

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

1 row in set (0.00 sec)  

MySQL的concat函数在连接字符串的时候,只要其中一个是NULL,那么将返回NULL


mysql> select concat('11','22',null);  

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

| concat('11','22',null) |  

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

| NULL   |  

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

1 row in set (0.00 sec)  

                                查看的一般步骤

查看所有库的大小

mysql> use information_schema;

Database changed

mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from TABLES;

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

| data     |

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

| 104.21MB |

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

1 row in set (0.11 sec)



查看指定库的大小

mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from TABLES where table_schema='jishi';

+---------+

| data    |

+---------+

| 26.17MB |

+---------+

1 row in set (0.01 sec)



查看指定库的指定表的大小

mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from TABLES where table_schema='jishi' and table_name='a_ya';

+--------+

| data   |

+--------+

| 0.02MB |

+--------+

1 row in set (0.00 sec)



查看指定库的索引大小

mysql> SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024), 2), ' MB') AS 'Total Index Size' FROM TABLES  WHERE table_schema = 'jishi';

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

| Total Index Size |

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

| 0.94 MB          |

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

1 row in set (0.01 sec)



查看指定库的指定表的索引大小



mysql> SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024), 2), ' MB') AS 'Total Index Size' FROM TABLES  WHERE table_schema = 'test' and table_name='a_yuser';

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

| Total Index Size |

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

| 21.84 MB         |

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

1 row in set (0.00 sec)

mysql> show create table test.a_yuser\G;

*************************** 1. row ***************************

      Table: a_yuser

Create Table: CREATE TABLE `a_yuser` (

 `email` varchar(60) NOT NULL DEFAULT '',

 `user_name` varchar(60) NOT NULL DEFAULT '',

 KEY `cc` (`email`(5)),

 KEY `ccb` (`user_name`(5)),

 KEY `ccbc` (`email`(5),`user_name`(5))

) ENGINE=MyISAM DEFAULT CHARSET=utf8

1 row in set (0.00 sec)



ERROR:

No query specified



mysql> select count(*) from test.a_yuser;

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

| count(*) |

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

|  1073607 |

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

1 row in set (0.00 sec)



mysql>

查看一个库中的情况...

mysql>  SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows/1000000,4),'M') AS 'Number of Rows', CONCAT(ROUND(data_length/(1024*1024*1024),4),'G') AS 'Data Size', CONCAT(ROUND(index_length/(1024*1024*1024),4),'G') AS 'Index Size', CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),4),'G') AS'Total'FROM information_schema.TABLES WHERE table_schema LIKE 'test';

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

| Table Name    | Number of Rows | Data Size | Index Size | Total   |

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

| test.a_br     | 0.4625M        | 0.0259G   | 0.0171G    | 0.0431G |

| test.a_skuclr | 0.7099M        | 0.0660G   | 0.0259G    | 0.0919G |

| test.a_yuser  | 1.0736M        | 0.0497G   | 0.0213G    | 0.0710G |

| test.test     | 0.0000M        | 0.0000G   | 0.0000G    | 0.0000G |

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