MYSQL-算⼀算1000万条数据⼤概占了多⼤磁盘空间假设有张表叫table_name;其中有四个字段
CREATE TABLE `table_name` (
id bigint(20) not null auto_increment,
detail varchar(2000),
createtime datetime,
validity int default '0',
primary key (id)
);
每个字段设计完成后占⽤的字节数
bigint 8字节
varchar 2000 字节
datetime 8字节
validity 4字节
算乘法计算占⽤磁盘:
(8+2000+8+4) * 10000000 = 20200000000 字节 == 18G
此时⼤概明⽩,为什么要在设计数据库的时候,采⽤最⼩类型的原则了吧
其实该计算公式仅为简单计算;mysql索引和表分离本⾝是分离,有时索引占⽤的磁盘空间可能⽐表占⽤的磁盘空间都要⼤!!参看SQL:
1. 库空间以及索引空间⼤⼩:
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;
2. 查询某个数据库内每张表的⼤⼩:
concat(truncate(index_length/1024/1024,2),' MB') as index_size
from information_schema.tables where TABLE_SCHEMA = 'metadata'mysql下载哪个盘
group by TABLE_NAME
order by data_length desc;
3.查看数据库中所有表的信息
SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name',
CONCAT(truncate(table_rows/1000000,2),'M') AS 'Number of Rows',
CONCAT(truncate(data_length/(1024*1024*1024),2),'G') AS 'Data Size',
CONCAT(truncate(index_length/(1024*1024*1024),2),'G') AS 'Index Size' ,
CONCAT(truncate((data_length+index_length)/(1024*1024*1024),2),'G') AS 'Total' FROM information_schema.TABLES WHERE table_schema LIKE 'metadata';
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论