mysql大量删除数据后表空间处理
根据年删除大量数据
复制1.rpt_analyte_item表
select * from rpt_analyte_item where YEAR(createTime) like '2018%' limit 10,5
select count(*) from rpt_analyte_item where YEAR(createTime) like '2018%';
delete from rpt_analyte_item where YEAR(createTime) like '2018%';
select count(*) from rpt_analyte_item where YEAR(createTime) like '2019%';
delete from rpt_analyte_item where YEAR(createTime) like '2019%';
2.sys_results表
select count(*) from sys_results where id <17000000;
delete from sys_results where id <17000000;
复制mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| lims-prod |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> use lims-prod;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select count(*) from rpt_analyte_item where YEAR(createTime) like '2018%';
+----------+
| count(*) |
+----------+
| 675259 |
+----------+
1 row in set (10.02 sec)
mysql> delete from rpt_analyte_item where YEAR(createTime) like '2018%';
Query OK, 675259 rows affected (1 min 6.70 sec)
mysql> select count(*) from rpt_analyte_item where YEAR(createTime) like '2019%';
+----------+
| count(*) |
+----------+
| 9019714 |
+----------+
1 row in set (15.22 sec)
mysql> delete from rpt_analyte_item where YEAR(createTime) like '2019%';
Query OK, 9019714 rows affected (9 min 31.89 sec)
mysql> select count(*) from sys_results where id <17000000;
+----------+
| count(*) |
+----------+
| 9839370 |
+----------+
1 row in set (2 min 44.05 sec)
mysql> delete from sys_results where id <17000000;
Query OK, 9839370 rows affected (20 min 57.12 sec)
空间释放处理
复制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_size DESC;
复制mysql> alter table rpt_analyte_item engine=innodb;
Query OK, 0 rows affected (1 min 42.41 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table sys_results engine=innodb;
Query OK, 0 rows affected (3 min 1.72 sec)
Records: 0 Duplicates: 0 Warnings: 0
执行后空间情况
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫