database operations

##View the storage capacity of each table in the database

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;

Note: Just change the database name

##View the size of all databases

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;

#Query the 0 o'clock of the current day, the format is YYYY-MM-DD HH:mm:ss
SELECT DATE_FORMAT(CURDATE(),'%Y-%m-%d %H:%i:%s');
#Query the 0 o'clock this week, the format is YYYY-MM-DD HH:mm:ss
SELECT DATE_FORMAT(DATE_ADD(CURDATE(),INTERVAL -WEEKDAY(CURDATE()) DAY),'%Y-%m-%d %H:%i:%s');
#Query the 0 o'clock of the current month, the format is YYYY-MM- DD HH:mm:ss
SELECT DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL DAY(CURDATE())-1 DAY),'%Y-%m-%d %H:%i:%s');

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324897699&siteId=291194637