1.数据库占用大小:
查询整个数据库已经存储占用的空间大小:
select concat(round(sum(data_length/1024/1024),2),'MB') as data_length_MB,concat(round(sum(index_length/1024/1024),2),'MB')
as index_length_MB
from information_schema.tables
where table_schema='sj';
thinkphp框架查询:
var_dump(M()->query("select concat(round(sum(data_length/1024/1024),2),'MB') as data_length_MB,concat(round(sum(index_length/1024/1024),2),'MB') as index_length_MB
from information_schema.tables
where table_schema='sj';
"));
打印结果:
array(1) {
[0]=> array(2) {
["data_length_mb"]=> string(6) "0.16MB"
["index_length_mb"]=> string(6) "0.13MB"
}
}
2.数据表占用大小:
查询整个数据表已经存储占用的空间大小:
select concat(round(sum(data_length/1024/1024),2),'MB') as data_length_MB,concat(round(sum(index_length/1024/1024),2),'MB') as index_length_MB
from information_schema.tables
where table_schema='sj' AND table_name='ds_user';
thinkphp框架查询:
var_dump(M()->query("select concat(round(sum(data_length/1024/1024),2),'MB') as data_length_MB,concat(round(sum(index_length/1024/1024),2),'MB') as index_length_MB
from information_schema.tables
where table_schema='sj' AND table_name='ds_user';
"));
打印结果:
array(1) {
[0]=> array(2) {
["data_length_mb"]=> string(6) "0.02MB"
["index_length_mb"]=> string(6) "0.00MB"
}
}