已索引
OS: RHEL 7.4
DB: MySQL 5.7.27
MySQL DB 服务器 CPU 使用率高(接近100%)故障
统一消息平台数据库主机 CPU 使用率告警,使用率接近 100%。
执行 show processlist,发现二十多个线程在做 update 操作,语句形如:
update xx_dialog_record
set read_status = 0
where msg_id = '3995284954425456370';
查询 slow.log:
# Time: 2025-05-20T16:30:21.960939+08:00
# User@Host: smsmysql[smsmysql] @ [10.31.0.198] Id: 1219506633
# Query_time: 9.587795 Lock_time: 0.000096 Rows_sent: 0 Rows_examined: 2869223
use zx_wechat_public;
SET timestamp=1747729821;
update xx_dialog_record
set read_status = 0
where msg_id = '3995284954425456370';
可以看到该语句运行了 9.58 秒,原因是 msg_id 列上没有索引,执行计划走的全表索引。
解决办法:在该列上创建索引。