mysql服务器cpu爆满解决办法
作者:互联网
mysql服务器cpu爆满解决办法_爱代码也爱生活-CSDN博客
碰到一个mysql cpu爆满的问题,简单记录下
步骤:
1、通过show processlist找到耗时最长的
mysql> show processlist;
+----+------+-----------------+------+---------+------+--------------+------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------------+------+---------+------+--------------+------------------------------------------------------------------------------------------------------+
| 19 | root | localhost:60604 | big | Query | 1533 | Sending data | SELECT count(*) num,city FROM `ih_user_temp` where city in (select city from ih_user_temp where city |
| 25 | root | localhost | NULL | Query | 0 | NULL | show processlist |
+----+------+-----------------+------+---------+------+--------------+------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
2、先杀掉该进程(command=Query)
mysql> kill 19;
Query OK, 0 rows affected (0.01 sec)
3、通过慢查询日志找到具体的sql语句
开启慢查询:
[mysqld]
slow_query_log=1 #开启慢查询
long_query_time=5 #慢查询时间
log-slow-queries = /var/log/mysql/slowquery.log #需有写入权限
4、使用explain 优化sql语句,参考: mysql使用explain优化sql语句
引起cpu过高的sql一般集中在order by、group by、批量insert、嵌套子查询等sql语句中
5、调整my.cnf的query_cache_size和tmp_table_size的值
————————————————
版权声明:本文为CSDN博主「爱代码也爱生活」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/nuli888/article/details/52435807
标签:city,log,mysql,爆满,sql,Query,cpu 来源: https://www.cnblogs.com/miaojx/p/15464752.html