当前位置:首页>开发>正文

如何查询mysql数据库的表的内容大小 如何查看MySQL中每张表占用的空间大小

2023-04-17 04:16:36 互联网 未知 开发

 如何查询mysql数据库的表的内容大小 如何查看MySQL中每张表占用的空间大小

如何查询mysql数据库的表的内容大小

查看mysql数据库大小的四种办法,分别有以下四种:
第一种:进去指定schema 数据库(存放了其他的数据库的信息)
use information_schema
第二种:查询所有数据的大小
select concat(round(sum(DATA_LENGTH/1024/1024),2),MB) as data from TABLES(http://www.6ddd.com)
第三种:查看指定数据库的大小,比如说:数据库apoyl
select concat(round(sum(DATA_LENGTH/1024/1024),2),MB) as data from TABLES where table_schema=apoyl
第四种:查看指定数据库的表的大小,比如说:数据库apoyl 中apoyl_test表
select concat(round(sum(DATA_LENGTH/1024/1024),2),MB) as data from TABLES where table_schema=apoyl and table_name=apoyl_test

如何查看MySQL中每张表占用的空间大小

如题,找到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=数据库名

如何查看SQL2000数据库中所有表的数据量大小

直接在查询分析器运行即可:
declare @id int
declare @type character(2)
declare @pages
int
declare @dbname sysname
declare @dbsize dec(15,0)
declare @bytesperpage dec(15,0)
declare @pagesperMB dec(15,0)

create table #spt_space
(
objid int null,
rows int null,
reserved dec(15) null,
data dec(15) null,
indexp dec(15) null,
unused dec(15) null
)

set nocount on

-- Create a cursor to loop through the user tables
declare c_tables cursor for
select id
from sysobjects
where xtype = U

open c_tables

fetch next from c_tables
into @id

while @@fetch_status = 0
begin

/* Code from sp_spaceused */
insert into #spt_space (objid, reserved)
select objid = @id, sum(reserved)
from sysindexes
where indid in (0, 1, 255)
and id = @id

select @pages = sum(dpages)
from sysindexes
where indid < 2
and id = @id
select @pages = @pages isnull(sum(used), 0)
from sysindexes
where indid = 255
and id = @id
update #spt_space
set data = @pages
where objid = @id

/* index: sum(used) where indid in (0, 1, 255) - data */
update #spt_space
set indexp = (select sum(used)
from sysindexes
where indid in (0, 1, 255)
and id = @id)
- data
where objid = @id

/* unused: sum(reserved) - sum(used) where indid in (0, 1, 255) */
update #spt_space
set unused = reserved
- (select sum(used)
from sysindexes
where indid in (0, 1, 255)
and id = @id)
where objid = @id

update #spt_space
set rows = i.rows
from sysindexes i
where i.indid < 2
and i.id = @id
and objid = @id

fetch next from c_tables
into @id
end

select TableName = (select left(name,60) from sysobjects where id = objid),
Rows = convert(char(11), rows),
ReservedKB = ltrim(str(reserved * d.low / 1024.,15,0) KB),
DataKB = ltrim(str(data * d.low / 1024.,15,0) KB),
IndexSizeKB = ltrim(str(indexp * d.low / 1024.,15,0) KB),
UnusedKB = ltrim(str(unused * d.low / 1024.,15,0) KB)

from #spt_space, master.dbo.spt_values d
where d.number = 1
and d.type = E
order by reserved desc
drop table #spt_space
close c_tables
deallocate c_tables

db2怎么列出当前数据库下所有表占用空间的大小

ADMINTABINFO administrative view and ADMIN_GET_TAB_INFO table function - Retrieve size and state information for tables

Example 1: Retrieve size and state information for all tables

SELECT * FROM SYSIBMADM.ADMINTABINFO

Example 2: Retrieve size and state information for the table DBUSER1.EMPLOYEE.

SELECT * FROM TABLE (SYSPROC.ADMIN_GET_TAB_INFO(DBUSER1, EMPLOYEE))
AS T
以上参考 http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.admin.doc/doc/r0022024.htm

DATA_OBJECT_L_SIZE DATA_OBJECT_P_SIZE这两个字段值为你需要的信息。
第一个示例查询时可以带上模式名或者表名来去除系统表的信息

如何查看当前用户所有表的表名,记录数,占用空间大小

查看当前用户下的所有表:
select * from all_tables where owner=Test

查看某表所占用的空间的大小:
select sum(bytes)/(1024*1024) "size" from user_segments where segment_name=app(aaa)

怎么查看实例所有用户表,索引大小,数据文件大小

table:
  select OWNER,SEGMENT_NAME,sum(BYTES)/1024/1024 M from dba_segments where SEGMENT_TYPE=TABLE group by SEGMENT_NAME

  index:
  select OWNER,SEGMENT_NAME,sum(BYTES)/1024/1024 M from dba_segments where SEGMENT_TYPE=INDEX group by SEGMENT_NAME

  数据文件大小
  select TABLESPACE_NAME,FILE_NAME,BYTES/1024/1024 M from dba_data_files order by TABLESPACE_NAME

oracle如何查看用户的表空间大小?

select t.tablespace_name,
round(t.bytes / 1024 / 1024 / 1024, 2) || G "总大小",
round((t.bytes - f.bytes) / 1024 / 1024 / 1024, 2) || G "已使用",
round(100 * (t.bytes - f.bytes) / t.bytes, 2) || % "使用率"
from (select tablespace_name, sum(bytes) bytes
from dba_data_files
group by tablespace_name) t,
(select tablespace_name, sum(bytes) bytes
from dba_free_space
group by tablespace_name) f
where f.tablespace_name( ) = t.tablespace_name

mysql表太多 怎样查看所有表

到mysql控制命令台,
use database_name
show tables
就可以列出database_name 下的所以表!  另外可以使用第三方软件比如Navicat;
或者mysql自带winmysqladmin.exe程序也可以查看 ,如图:

最新文章