MySQL 8 故障
·
日期: 2026-06-10 服务器: jenkins (15GB RAM) MySQL 版本: 8.0.37
问题现象
-
InnoDB 缓冲区压力告警 — 日志中大量重复警告:
[Warning] [MY-011959] [InnoDB] Difficult to find free blocks in the buffer pool (30000~60000 search iterations)! Consider increasing the buffer pool size.
-
连接数耗尽 — 客户端报错:
ERROR 1040 (HY000): Too many connections
根因分析
| 问题 | 原因 |
|---|---|
| 缓冲区压力 | innodb_buffer_pool_size 使用默认值 128MB,远不足以承载工作负载 |
| 连接耗尽 | max_connections 使用默认值 151,并发连接数已达上限 |
| 配置未生效 | /etc/mysql/my.cnf 缺少 !includedir /etc/mysql/mysql.conf.d/,导致 mysqld.cnf 从未被读取 |
服务器同时运行 Elasticsearch (~3.7GB)、etcd (~1.4GB)、QuestDB (~1GB),可用内存约 4.7GB。
修复步骤
1. 调整 MySQL 参数
编辑 /etc/mysql/mysql.conf.d/mysqld.cnf,在 [mysqld] 段末尾添加:
innodb_buffer_pool_size = 4G max_connections = 300
2. 修复配置文件加载路径
编辑 /etc/mysql/my.cnf,添加 mysql.conf.d/ 目录的包含指令:
!includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/ # 新增 !includedir /etc/mysql/mariadb.conf.d/
3. 重启 MySQL
原进程因缓冲区脏页无法刷盘,graceful shutdown 卡住超过 10 分钟,最终通过 kill -9 强制终止后重启:
kill -9 <mysqld_pid> systemctl start mysql
4. 验证修复结果
SHOW VARIABLES LIKE 'innodb_buffer_pool_size'; -- 4294967296 (4GB) SHOW VARIABLES LIKE 'max_connections'; -- 300 SHOW STATUS LIKE 'Threads_connected'; -- 13
systemctl status mysql ● mysql.service - MySQL Community Server Active: active (running) Status: "Server is operational"
日志中不再出现 buffer pool 警告。
修改文件清单
| 文件 | 修改内容 |
|---|---|
/etc/mysql/mysql.conf.d/mysqld.cnf |
新增 innodb_buffer_pool_size = 4G 和 max_connections = 300 |
/etc/mysql/my.cnf |
新增 !includedir /etc/mysql/mysql.conf.d/ |
更多推荐



所有评论(0)