查看mysql数据库容量大小 第一种情况查询所有数据库的总大小方法如下mysql use information_schema;mysql select concat(round(sum(DATA_LENGTH/1024/1024),2),MB) as data from TABLES;-----------| data |-----------| 3052.76MB |-----------1 row in set (0.02 sec)统计一下所有库数据量每张表数据量AVG_ROW_LENGTH*TABLE_ROWSINDEX_LENGTHSELECTSUM(AVG_ROW_LENGTH*TABLE_ROWSINDEX_LENGTH)/1024/1024 AS total_mbFROM information_schema.TABLES统计每个库大小SELECTtable_schema,SUM(AVG_ROW_LENGTH*TABLE_ROWSINDEX_LENGTH)/1024/1024 AS total_mbFROM information_schema.TABLES group by table_schema;第二种情况查看指定数据库的大小比如说数据库test方法如下mysql use information_schema;mysql select concat(round(sum(DATA_LENGTH/1024/1024),2),MB) as data from TABLES where table_schematest;----------| data |----------| 142.84MB |----------1 row in set (0.00 sec)1.查看所有数据库各容量大小selecttable_schema as 数据库,sum(table_rows) as 记录数,sum(truncate(data_length/1024/1024, 2)) as 数据容量(MB),sum(truncate(index_length/1024/1024, 2)) as 索引容量(MB)from information_schema.tablesgroup by table_schemaorder by sum(data_length) desc, sum(index_length) desc;2.查看所有数据库各表容量大小selecttable_schema as 数据库,table_name as 表名,table_rows as 记录数,truncate(data_length/1024/1024, 2) as 数据容量(MB),truncate(index_length/1024/1024, 2) as 索引容量(MB)from information_schema.tablesorder by data_length desc, index_length desc;3.查看指定数据库容量大小例查看mysql库容量大小selecttable_schema as 数据库,sum(table_rows) as 记录数,sum(truncate(data_length/1024/1024, 2)) as 数据容量(MB),sum(truncate(index_length/1024/1024, 2)) as 索引容量(MB)from information_schema.tableswhere table_schemamysql;4.查看指定数据库各表容量大小例查看mysql库各表容量大小selecttable_schema as 数据库,table_name as 表名,table_rows as 记录数,truncate(data_length/1024/1024, 2) as 数据容量(MB),truncate(index_length/1024/1024, 2) as 索引容量(MB)from information_schema.tableswhere table_schemamysqlorder by data_length desc, index_length desc;