1、查询整个mysql数据库,整个库的大小;单位转换为MB。
林周网站建设公司创新互联,林周网站设计制作,有大型网站制作公司丰富经验。已为林周成百上千家提供企业网站建设服务。企业网站搭建\成都外贸网站制作要多少钱,请找那个售后服务好的林周做网站的公司定做!
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from information_schema.TABLES
2、查询mysql数据库,某个库的大小;
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data
from information_schema.TABLES
where table_schema = 'testdb'
3、查看库中某个表的大小;
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data
from information_schema.TABLES
where table_schema = 'testdb'
and table_name = 'test_a';
4、查看mysql库中,test开头的表,所有存储大小;
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data
from information_schema.TABLES
where table_schema = 'testdb'
and table_name like 'test%';
--1、查看表空间的名称及大小
select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;
--2、查看表空间物理文件的名称及大小
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
mysql show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hnmcc |
| hnmcc_ecp |
| hnmcc_push |
| hnmcc_sso |
| mysql |
| percona |
| performance_schema |
| test |
+--------------------+
9 rows in set (0.00 sec)
// 使用mysql自带管理表information_schema.
mysql use information_schema;
mysql select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='hnmcc' and table_name='l_log_20160102';
+-----------+
| data |
+-----------+
| 4803.00MB |
+-----------+
1 row in set (0.00 sec)
如题,找到MySQL中的information_schema表,这张表记录了所有数据库中表的信息,主要字段含义如下:
TABLE_SCHEMA : 数据库名
TABLE_NAME:表名
ENGINE:所使用的存储引擎
TABLES_ROWS:记录数
DATA_LENGTH:数据大小
INDEX_LENGTH:索引大小
如果需要查询所有数据库占用空间大小只需要执行SQL命令:
mysql use information_schema
Database changed
mysql SELECT sum(DATA_LENGTH+INDEX_LENGTH) FROM TABLES;
+-------------------------------+
| sum(DATA_LENGTH+INDEX_LENGTH) |
+-------------------------------+
| 683993 |
+-------------------------------+
1 row in set (0.00 sec)
大小是字节数 如果想修改为KB可以执行:
SELECT sum(DATA_LENGTH+INDEX_LENGTH)/1024 FROM TABLES;
如果修改为MB应该也没问题了吧
如果需要查询一个数据库所有表的大小可以执行:
SELECT sum(DATA_LENGTH+INDEX_LENGTH) FROM TABLES WHERE TABLE_SCHEMA='数据库名'
查询所有数据库占用磁盘空间大小的SQL语句:
复制代码
代码如下:
select
TABLE_SCHEMA,
concat(truncate(sum(data_length)/1024/1024,2),'
MB')
as
data_size,
concat(truncate(sum(index_length)/1024/1024,2),'MB')
as
index_size
from
information_schema.tables
group
by
TABLE_SCHEMA
order
by
data_length
desc;
查询单个库中所有表磁盘占用大小的SQL语句:
复制代码
代码如下:
select
TABLE_NAME,
concat(truncate(data_length/1024/1024,2),'
MB')
as
data_size,
concat(truncate(index_length/1024/1024,2),'
MB')
as
index_size
from
information_schema.tables
where
TABLE_SCHEMA
=
'TestDB'
group
by
TABLE_NAME
order
by
data_length
desc;
以上语句测试有效,注意替换以上的TestDB为数据库名
1、进去指定schema 数据库(存放了其他的数据库的信息)\x0d\x0ause information_schema\x0d\x0a2、查询所有数据的大小\x0d\x0aselect concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES\x0d\x0a3、查看指定数据库的大小\x0d\x0a比如说 数据库apoyl\x0d\x0aselect concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='apoyl';\x0d\x0a4、查看指定数据库的表的大小\x0d\x0a比如说 数据库apoyl 中apoyl_test表\x0d\x0aselect concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='apoyl' and table_name='apoyl_test';\x0d\x0a整完了,有兴趣的可以试哈哦!挺使用哈\x0d\x0a网站找的,都是正解