要想知道每个数据库的大小的话,步骤如下:
1、进入information_schema 数据库(存放了其他的数据库的信息)
use information_schema;
2、查询所有数据的大小:
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;
3、查看指定数据库的大小:
比如查看数据库home的大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home';
4、查看指定数据库的某个表的大小
比如查看数据库home中 members 表的大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home' and table_name='members';
查看MySQL数据库大小
1.首先进入information_schema 数据库(存放了其他的数据库的信息)
mysql> use information_schema;Database changed
2.查看大小
(1)查看所有数据库大小
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES;
结果:
(2)查看指定数据库大小
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='CarData';
结果
(3)查看指定数据库的指定表单的大小
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='CarData' and table_name='driver020294';
结果
查看指定数据库指定表单的其他大小:
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data_size,
-> concat(round(sum(MAX_DATA_LENGTH/1024/1024),2),'MB') as max_data_size,
-> concat(round(sum(INDEX_LENGTH/1024/1024),2),'MB') as index_size,
-> concat(round(sum(DATA_FREE/1024/1024),2),'MB') as data_free
-> from TABLES where table_schema='CarData' and table_name='driver020294';
结果:
注:第一步也可以不用使用数据库,直接像下面这样写;
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data_size,
-> concat(round(sum(MAX_DATA_LENGTH/1024/1024),2),'MB') as max_data_size,
-> concat(round(sum(INDEX_LENGTH/1024/1024),2),'MB') as index_size,
-> concat(round(sum(DATA_FREE/1024/1024),2),'MB') as data_free
-> from INFORMATION_SCHEMA.TABLES where table_schema='CarData' and table_name='driver020294';
结果是一样的: