一:查询数据库中表占比比较多的表
SELECT
table_name AS "Tables",
round(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.tables
WHERE table_schema = "自己的数据库名";
二:发现eb_exception_log这一个表占据25G
三:删除历史数据
-- 创建临时表
CREATE TABLE eb_exception_log_temp LIKE eb_exception_log;
-- 插入需要保留的数据
Tips:查看是否创建索引,否则下面执行插入会很慢:
【ALTER TABLE eb_exception_log ADD INDEX idx_create_time (create_time)】
INSERT INTO eb_exception_log_temp
SELECT * FROM eb_exception_log
WHERE create_time > '2025-01-01 00:00:00';
-- 删除原表
DROP TABLE eb_exception_log;
-- 重命名临时表
ALTER TABLE eb_exception_log_temp RENAME TO eb_exception_log;
删除表数据后,磁盘使用率瞬间降下来: