Home > Database > Mysql Tutorial > body text

解决mysql占用cpu资源100%的问题_MySQL

WBOY
Release: 2016-06-01 13:37:34
Original
1036 people have browsed it

bitsCN.com


解决mysql占用cpu资源100%的问题

 

一个Win2003服务器,以前就跑了一个tomcat实例也没用nginx做前端代理,这个tomcat里面带了不少网站,但是访问量并不是很大,基本属于业务集中型。

解决的过程其实也挺easy,这里记录一下思路。

首先把mysql服务器升级到最新的版本,尽量避免是mysql本身问题。

然后在my.ini里面mysqld里面配置:

slow-query-log = 1

slow-query-log-file = slow.log

重启mysql这样所有'slow'的都会记录到日志里面。

     

然后再到慢的时候就能看到具体什么sql引发了慢的问题(slow.log在datadir下),最后发现慢的那个表查询里面username没有加索引而且并发不小,开始数据不多还没问题,后来数据多了些达到了十几万的时候,并发查没索引的表就出来问题了,每次比较十几万次字符串是挺要命。

 

给这个字段加上索引,马上cpu就降下来了。

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!