##查看数据库每个表的存储容量

SELECT aa.TABLE_NAME,aa.data_size,aa.index_size,aa.data_size+aa.index_size as table_size
from 
(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 = 'xxxx'
group by TABLE_NAME
order by data_length desc) aa;

注:把数据库名改好就可以了

##查看所有数据库的大小

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;

#查询当天0点,格式为YYYY-MM-DD HH:mm:ss
SELECT DATE_FORMAT(CURDATE(),'%Y-%m-%d %H:%i:%s');
#查询本周0点,格式为YYYY-MM-DD HH:mm:ss
SELECT DATE_FORMAT(DATE_ADD(CURDATE(),INTERVAL -WEEKDAY(CURDATE()) DAY),'%Y-%m-%d %H:%i:%s');
#查询本月0点,格式为YYYY-MM-DD HH:mm:ss
SELECT DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL DAY(CURDATE())-1 DAY),'%Y-%m-%d %H:%i:%s');