数据盘点查询语句

use lk_clud;

/*数据大小和索引大小   TABLE_SCHEMA改为数据库名即可*/
/*table_size 通常指的是一个表(table)在存储介质上所占用的总空间大小。这个大小通常包括表的数据部分(data)和索引部分(index),有时还可能包括其他与表相关的元数据或存储开销
*/
SELECT TABLE_NAME,
       CONCAT(TRUNCATE(SUM(data_length) / 1024 / 1024, 2), ' MB') AS data_size,
       CONCAT(TRUNCATE(SUM(index_length) / 1024 / 1024, 2), ' MB') AS index_size,
       CONCAT(TRUNCATE((SUM(data_length) + SUM(index_length)) / 1024 / 1024, 2), ' MB') AS table_size
FROM information_schema.tables
WHERE TABLE_SCHEMA = 'lk_clud'
GROUP BY TABLE_NAME
ORDER BY SUM(data_length) DESC;


/*建表时间   table_name改为数据表名即可*/
SELECT date_format(create_time, '%Y年%m月%d日 %H:%i:%s') AS create_time,table_name
FROM information_schema.tables
WHERE table_schema = database() AND table_name = 'auth_user';


/*一个库的数据  table_schema改为数据库名即可*/
select
table_schema as '数据库',
table_name as '表名',
table_comment as '表注释',
table_rows as '记录数',
truncate(data_length/1024/1024, 2) as '数据容量(MB)',
truncate(index_length/1024/1024, 2) as '索引容量(MB)'
from information_schema.tables
where table_schema='lk_clud'
order by table_rows desc, index_length desc;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

豆浆-plus

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值