1、查看监控,发现整点时间有写IO过高情况
2、iotop 分析确认io高峰是由mysql导致的
3、开启general log,分析SQL
set global general_log = on ;
4、观察binlog 与 general log 发现 文件增长量不大,怀疑不是有Insert 与 update 与 delete 导致的 写IO过高
5、show full processlist ;发现有慢SQL
*************************** 6. row ***************************
Id: 337153
User: user_car_bill
Host: 192.168.3.10:63018
db: yoolifin
Command: Query
Time: 295
State: Creating sort index
Info: SELECT 1 AS `Number of Records`,
`自定义 SQL 查询`.`实还金额` AS `实还金额`,
`自定义 SQL 查询`.`应还客户数` AS `应还客户数`,
`自定义 SQL 查询`.`应还金额` AS `应还金额`,
`自定义 SQL 查询`.`累计发过代扣客户数` AS `累计发过代扣客户数`,
`自定义 SQL 查询`.`累计客户覆盖率` AS `累计客户覆盖率`,
`自定义 SQL 查询`.`累计还款收回率` AS `累计还款收回率`,
`自定义 SQL 查询`.`还款日发过代扣客户数` AS `还款日发过代扣客户数`,
`自定义 SQL 查询`.`还款日客户覆盖率` AS `还款日客户覆盖率`,
`自定义 SQL 查询`.`还款日期` AS `还款日期`,
`自定义 SQL 查询`.`还款日还款收回率` AS `还款日还款收回率`
FROM (
select a.dt 还款日期,a.c 应还客户数,a.totle_repayment 应还金额,a.fact_repayment 实还金额, a.fact_repayment/a.totle_repayment 累计还款收回率, a.very_fact_repayment/a.totle_repayment 还款日还款收回率,t.c 还款日发过代扣客户数,t.c/a.c 还款日客户覆盖率,tt.c 累计发过代扣客户数,tt.c/a.c 累计客户覆盖率
FROM(
select date(payment_date) dt,count(DISTINCT APP_NO) c,sum(totle_repayment) totle_repayment,sum(fact_repayment) fact_repayment ,sum(if(payment_date=fact_payment_date,fact_repayment,0)) very_fact_repayment
from fin_repayment m
where
date(payment_date)>'2017-06-01' and date(payment_date)<=date(curdate() + INTERVAL 20 DAY) and DATE_FORMAT(payment_date,'%d') in ('05','20')
and m.`status` in ('1','2','5')
and ifnull(cut_chanl,0)<>3
group by date(payment_date)
) a
left join (
select date(n.SUBMIT_TIME) dt,count(DISTINCT APP_NO) c
from fin_back_info n
where date(n.SUBMIT_TIME)>'2017-06-01' and DATE_FORMAT(n.SUBMIT_TIME,'%d') in ('05','20') and n.PAYMENT_DATE=DATE(n.SUBMIT_TIME)
group by date(n.SUBMIT_TIME)
) t
on a.dt=t.dt
left join (
select date(n.PAYMENT_DATE) dt,count(DISTINCT APP_NO) c from fin_back_info n
where date(n.SUBMIT_TIME)>'2017-06-01'
group by date(n.PAYMENT_DATE)
) tt
on a.dt=tt.dt
) `自定义 SQL 查询`
*************************** 6. row ***************************
6、分析慢SQL,产生大量的派生表,可能是由于内存不够,写入磁盘导致的IO过高
7、执行该SQL,观看监控,产生IO高峰,确认为该SQL导致的IO瓶颈过高