时间:2021-07-01 10:21:17 帮助过:3人阅读
然后进入mysql的慢查询语句的目录下面,看下slow.log
select count( *) as col_0_0_ from card_received cardreceiv0_ where (cardreceiv0_.statusCode= ‘1‘ or cardreceiv0_.statusCode= ‘2‘ ) and (cardreceiv0_.ownerCardNum= ‘8757003738566209‘ or cardreceiv0_.ownerPhoneNum= ‘13724689717‘ ) and cardreceiv0_.readStatus=0\G;发现这条查询语句耗时5秒左右,但是slow.log里面全部是这条语句。所以我觉得很可疑。
再用explain分析下看
mysql> explain select count(*) as col_0_0_ from card_received cardreceiv0_ where (cardreceiv0_.statusCode=‘1‘ or cardreceiv0_.statusCode=‘2‘) and (cardreceiv0_.ownerCardNum=‘8757003738566209‘ or cardreceiv0_.ownerPhoneNum=‘13724689717‘) and cardreceiv0_.readStatus=0\G; explain结果: ************************** 1. row *************************** id: 1 select_type: SIMPLE table: cardreceiv0_ type: ref possible_keys: readStatus,ownerCardNum,statusCode,ownerPhoneNum key: readStatus key_len: 5 ref: const rows: 2394190 Extra: Using where 1 row in set (0.00 sec) ERROR: No query specified
居然扫描了:2394190行。。。。
最后跟开发沟通后,因为这边表数据并不重要。故将一些旧数据情况了,表示已经清空了200万行!最后mysql的cpu终于降下来了。。。
不过要彻底解决问题,仍需要优化语句,建立索引哪。。不然数据多了,肯定还会出问题的。
好了,此次故障也仅仅给提供一些解决问题的思路。具体问题还是需要具体分析的。
本文出自 “IT--小哥” 博客,请务必保留此出处http://402753795.blog.51cto.com/10788998/1761719
mysql数据库cpu、mem使用率高的解决案例
标签:mysql