查询数据库表数据量大小

1.查询各个表的数据量大小

use information_schema;
SELECT
TABLE_NAME,
(DATA_LENGTH/1024/1024) as DataM ,
(INDEX_LENGTH/1024/1024) as IndexM,
((DATA_LENGTH+INDEX_LENGTH)/1024/1024) as AllM,
TABLE_ROWS
FROM
TABLES
WHERE
TABLE_SCHEMA = '数据库名'
order by table_rows desc;

2.查询一张表每个月产生的数据量

select
DATE_FORMAT(create_time, '%Y-%m') as date,count(*) as monthcount
from
表名
GROUP BY date
ORDER BY monthcount desc; 

你可能感兴趣的:(后端开发,mysql)