mysql查看表空间占用情况

今天想起查看下mysql表空间大小,忘记命令了,在此记下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
${database} 为数据库的名称

/*1.查看数据库索引空间大小

(1)单位是GB*/

SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024*1024), 6), ' GB') AS 'Total Index Size'
FROM information_schema.TABLES WHERE table_schema LIKE '${database}';
/*
+------------------+
| Total Index Size |
+------------------+
| 1.70 GB |
+------------------+
*/
/*
(2)单位是MB
*/
SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024), 6), ' MB') AS 'Total Index Size'
FROM information_schema.TABLES WHERE table_schema LIKE '${database}';
/*
其中“database”为你所要查看的数据库
*/

/*
2.查看表空间大小
*/
SELECT CONCAT(ROUND(SUM(data_length)/(1024*1024*1024), 6), ' GB') AS 'Total Data Size'
FROM information_schema.TABLES WHERE table_schema LIKE '${database}';
/*
+-----------------+
| Total Data Size |
+-----------------+
| 3.01 GB |
+-----------------+
*/
/*
3.查看数据库中所有表空间信息
*/
SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name',
table_rows AS 'Number of Rows',
CONCAT(ROUND(data_length/(1024*1024*1024),6),' G') AS 'Data Size',
CONCAT(ROUND(index_length/(1024*1024*1024),6),' G') AS 'Index Size' ,
CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),6),' G') AS'Total'
FROM information_schema.TABLES
WHERE table_schema LIKE '${database}';