故障:mysql
晚上大概7點鐘左右,收到播放中心投訴,說視頻播放很慢,加載好久不出來。一開始,哥覺得是tomcat服務又掛了。因此到tomcat服務器上查看下catalina.out輸出日誌。卻沒發現任務錯誤信息。
sql
分析:數據庫
想了想,視頻加載慢,會不會是數據庫問題呢?果斷上mysql數據庫(從庫)看下top以下:tomcat
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 37258 mysql 20 0 17.2g 12g 5032 S 769.5 81.3 4383:29 mysqld
沒想到cpu竟然達到769%了!bash
而後進入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裏面所有是這條語句。因此我以爲很可疑。ide
再用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行。。。。spa
最後跟開發溝通後,由於這邊表數據並不重要。故將一些舊數據狀況了,表示已經清空了200萬行!最後mysql的cpu終於降下來了。。。日誌
不過要完全解決問題,仍須要優化語句,創建索引哪。。否則數據多了,確定還會出問題的。
好了,這次故障也僅僅給提供一些解決問題的思路。具體問題仍是須要具體分析的。