如何计算mysql数据库大小

如何计算mysql数据库大小,第1张

查看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'

防止存储空间不足。根据对表大小的估算,进而可以估算出整个数据库的大小。在项目测试阶段,可以根据所有对象进行估算,从而可以估算出系统上线以后数据库的大小,根据这些数据可以规划存储。这里要注意一点,要给备份留足存储空间。一般备份需要的空间是DB的2-3倍。如果DB是100G,那么给备份的空间最好是200G以上。

1. 查看所有表空间大小 SQL>select tablespace_name,sum(bytes)/1024/1024 from dba_data_files 2 group by tablespace_name2. 已经使用的表空间大小 SQL>select tablespace_name,sum(bytes)/1024/1024 from dba_free_space 2 group by tablespace_name3. 所以使用空间可以这样计算 select a.tablespace_name,total,free,total-free used from ( select tablespace_name,sum(bytes)/1024/1024 total from dba_data_files group by tablespace_name) a, ( select tablespace_name,sum(bytes)/1024/1024 free from dba_free_space group by tablespace_name) b where a.tablespace_name=b.tablespace_name4. 下面这条语句查看所有segment的大小。 Select Segment_Name,Sum(bytes)/1024/1024 From User_Extents Group By Segment_Name 5. 还有在命令行情况下如何将结果放到一个文件里。 SQL>spool out.txt SQL>select * from v$databaseSQL>spool off


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/6653946.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-26
下一篇 2023-03-26

发表评论

登录后才能评论

评论列表(0条)

保存