返回>大型高并发系统中,10大MySQL 生产事故-CSDN博客
一、问题现象
- ERROR 1030 (HY000): Got error 28 from storage engine。
- 磁盘空间100%,数据库不可写。
- binlog、undo log、表文件异常膨胀。
二、根本成因
分类 | 具体原因 |
---|---|
表数据过大 | 历史数据未归档 |
binlog 积压 | 未清理 |
undo log 积压 | 长事务未提交 |
临时文件膨胀 | 排序/分组落盘 |
relay log 堆积 | 主从延迟大 |
表空间碎片 | delete 后空间未回收 |
三、排查步骤
df -h
du -sh /var/lib/mysql/*
du -sh /var/lib/mysql/ib*
du -sh /var/lib/mysql/*.ibd
du -sh /var/lib/mysql/mysql-bin.*
show slave status\G;
show binary logs;
select * from information_schema.innodb_trx where TIME_TO_SEC(TIMEDIFF(now(), trx_started)) > 60;
四、优化方案
1. 清理 binlog
purge binary logs before now() - interval 7 day;
配置自动清理:
binlog_expire_logs_seconds = 604800
2. undo log 优化
- 提交长事务。
- innodb_undo_log_truncate = 1 (MySQL 8.0)
3. 表归档与冷热分离
- 分区表、历史表拆分。
4. 表膨胀收缩
optimize table big_table;
或 dump 重建。
5. relay log 优化
relay_log_purge = 1
6. 临时表与内存优化
tmp_table_size = 512M
max_heap_table_size = 512M
7. 文件系统扩容
- 临时扩容、挂盘。
- 清理无关日志。
五、生产示例
-
binlog 清理:
purge binary logs before now() - interval 3 day;
-
历史数据归档:
insert into orders_archive select * from orders where create_time < '2023-01-01'; delete from orders where create_time < '2023-01-01'; optimize table orders;
-
临时表优化:
tmp_table_size = 1G
六、监控与预防
监控项 | 工具 | 警戒值 |
---|---|---|
磁盘空间 | node_exporter | >80% |
binlog 文件数 | mysql_exporter | >100 |
undo log 空间 | information_schema | 异常增长 |
临时表磁盘使用 | Created_tmp_disk_tables | 异常增大 |
relay log 空间 | Relay_Log_Space | 膨胀告警 |
七、总结
binlog定时清,undo靠小事务,大表要归档,空间要optimize。