Home >Database >Mysql Tutorial >MySQL数据库CPU飙升紧急处理方法

MySQL数据库CPU飙升紧急处理方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 16:40:131264browse

Note: There is a file embedded within this post, please visit this post to download the file. MySQL数据库CPU飙升紧急处理方法 运行平稳的数据库,如果遇到CPU狂飙,到80%左右,那一定是开发写的烂SQL导致的,DBA首先要保证的是,数据库别跑挂了,所以

Note: There is a file embedded within this post, please visit this post to download the file.

MySQL数据库CPU飙升紧急处理方法

运行平稳的数据库,如果遇到CPU狂飙,到80%左右,那一定是开发写的烂SQL导致的,DBA首先要保证的是,数据库别跑挂了,所以我们要把那些运行慢的SQL杀死并记录到文件里,以便后面的排查。这里用到一个工具pt-kill,它可以帮助你。

1

pt-kill? -<span style="color: #ff0000;">-</span>match-info <span style="color: #ff0000;">"^</span>(select|SELECT)<span style="color: #ff0000;">"</span> -<span style="color: #ff0000;">-</span>busy-time 3 -<span style="color: #ff0000;">-</span>victim all -<span style="color: #ff0000;">-</span>interval 1 -<span style="color: #ff0000;">-</span>kill -<span style="color: #ff0000;">-</span>print --daemonize > /root/kill.txt

解释:只把select耗时3秒以上的SQL全部杀死,并打印出来。

模拟测试

这样就给杀死了,然后查看LOG。

会把杀死的SQL记录下来,然后再跟开发慢慢排查,有问题的SQL一定不能让开发随意上线的!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn