我正在測試一個網頁(wordpress),我有這個日誌,但我不能理解哪些是真正緩慢的查詢這裏是鏈接來閱讀我的網站的查詢,請找時間告訴我什麼是危險的查詢此日誌殺死我的CPU如何找到真正慢的查詢?
http://balkanweb.com/mysql_slow.log
我正在測試一個網頁(wordpress),我有這個日誌,但我不能理解哪些是真正緩慢的查詢這裏是鏈接來閱讀我的網站的查詢,請找時間告訴我什麼是危險的查詢此日誌殺死我的CPU如何找到真正慢的查詢?
http://balkanweb.com/mysql_slow.log
最好的免費工具來使用與慢查詢日誌的工作是PT-查詢摘要。默認情況下,這會生成一份報告,向您顯示您的聚合響應時間將按照查詢指紋進行細分。
我下載了你的日誌,並通過pt-query-digest運行它。這裏的輸出,這是查詢的排名列表的一部分,他們是如何花費的時間的一些統計數據:
# Profile
# Rank Query ID Response time Calls R/Call V/M Item
# ==== ================== ================ ===== ======== ===== ==========
# 1 0xC52F6DEC37D30D44 15065.0357 51.6% 80 188.3129 3.18 SELECT bwp_options
# 2 0x4876D9B1B390C783 4989.7583 17.1% 28 178.2057 7.91 SELECT bwp_options
# 3 0xE6593111E942BBD2 2337.6846 8.0% 10 233.7685 2.10 UPDATE bwp_options
# 4 0xF25CBDE8A6D65826 1784.7358 6.1% 8 223.0920 1.23 SELECT bwp_postmeta
# 5 0xC19DB36FFE85363C 1225.1890 4.2% 5 245.0378 0.09 SELECT bwp_terms bwp_term_taxonomy
# 6 0x7AC4A4CA8054E73D 981.1785 3.4% 4 245.2946 0.10 SELECT bwp_terms bwp_term_taxonomy bwp_term_relationships
# 7 0x3C55C7D48BD1B7C5 714.0035 2.4% 3 238.0012 0.00 SELECT bwp_term_relationships bwp_term_taxonomy
# 8 0x3A5E09EFF2C9AA73 487.4629 1.7% 2 243.7314 0.08 UPDATE bwp_postmeta
# 9 0x6545AED3996807BC 460.0886 1.6% 2 230.0443 0.22 SELECT bwp_postmeta
# 13 0x7AEDF19FDD3A33F1 207.8139 0.7% 30 6.9271 1.11 SELECT wp_options
# MISC 0xMISC 962.7022 3.3% 25 38.5081 0.0 <12 ITEMS>
你可以看到,#1查詢是不是在平均188秒的最慢的,但通話次數(80次)高於其他次數,因此佔總響應時間的最多。那#1查詢如下:
SELECT option_value FROM bwp_options WHERE option_name = 'ossdl_https' LIMIT 1
我建議,你需要在該表上option_name
列的索引。
其他幾個查詢的運行時間很長,平均在178到245秒之間。您應該使用索引優化所有這些查詢。事實上,它們太慢了,我不知道你是否有一臺資源不足的服務器。你換了嗎?
這裏是給你介紹幾個不錯的博客文章PT-查詢摘要:
PT-查詢消化是部分Percona Toolkit,這是一個免費的開放源碼集合,用於處理MySQL和Percona Server的腳本工具。
時間服用查詢是,
Count: 1 Time=2.90s (2s) Lock=0.00s (0s) Rows=1.0 (1), balkanwe_site[balkanwe_site]@localhost
SELECT bwp_posts.* FROM bwp_posts WHERE N=N AND (((bwp_posts.post_title LIKE 'S') OR (bwp_posts.post_content LIKE 'S')) AND ((bwp_posts.post_title LIKE 'S') OR (bwp_posts.post_content LIKE 'S'))) AND (bwp_posts.post_password = 'S') AND bwp_posts.post_type IN ('S', 'S', 'S', 'S', 'S') AND (bwp_posts.post_status = 'S') ORDER BY (CASE WHEN bwp_posts.post_title LIKE 'S' THEN N WHEN bwp_posts.post_title LIKE 'S' AND bwp_posts.post_title LIKE 'S' THEN N WHEN bwp_posts.post_title LIKE 'S' OR bwp_posts.post_title LIKE 'S' THEN N WHEN bwp_posts.post_content LIKE 'S' THEN N ELSE N END), bwp_posts.post_date DESC
Count: 1 Time=2.96s (2s) Lock=0.00s (0s) Rows=1.0 (1), balkanwe_site[balkanwe_site]@localhost
SELECT SQL_CALC_FOUND_ROWS bwp_posts.ID FROM bwp_posts WHERE N=N AND (((bwp_posts.post_title LIKE 'S') OR (bwp_posts.post_content LIKE 'S')) AND ((bwp_posts.post_title LIKE 'S') OR (bwp_posts.post_content LIKE 'S'))) AND (bwp_posts.post_password = 'S') AND bwp_posts.post_type IN ('S', 'S', 'S', 'S', 'S') AND (bwp_posts.post_status = 'S') ORDER BY (CASE WHEN bwp_posts.post_title LIKE 'S' THEN N WHEN bwp_posts.post_title LIKE 'S' AND bwp_posts.post_title LIKE 'S' THEN N WHEN bwp_posts.post_title LIKE 'S' OR bwp_posts.post_title LIKE 'S' THEN N WHEN bwp_posts.post_content LIKE 'S' THEN N ELSE N END), bwp_posts.post_date DESC LIMIT N, N
Count: 2 Time=1.57s (3s) Lock=0.00s (0s) Rows=20.0 (40), balkanwe_wp[balkanwe_wp]@localhost
(SELECT n.IDNotizia, n.Titolo, n.IDCategoria, n.Data, n.Descrizione, N AS Notizia FROM notizie AS n, notizie_legami AS nl WHERE n.IDNotizia=nl.IDNotizia AND n.Online='S' AND (n.Pubblicail='S' OR n.Pubblicail IS NULL) AND (n.Titolo LIKE 'S' OR n.Sottotitolo LIKE 'S' OR n.Descrizione LIKE 'S' OR n.Notizia like 'S') GROUP BY nl.IDCollegamento) UNION (SELECT IDNews, Titolo, IDCategoria, Data, News, N AS Notizia FROM news WHERE id_ext!='S' AND (Titolo LIKE 'S' OR News LIKE 'S')) ORDER BY Data DESC LIMIT N
Count: 1 Time=1.88s (1s) Lock=0.00s (0s) Rows=16.0 (16), root[root]@localhost
SELECT TABLE_SCHEMA as DB,SUM(DATA_LENGTH)+SUM(INDEX_LENGTH) AS SPACEUSED from information_schema.tables GROUP BY TABLE_SCHEMA
Count: 1 Time=1.06s (1s) Lock=0.00s (0s) Rows=20.0 (20), balkanwe_wp[balkanwe_wp]@localhost
(SELECT n.IDNotizia, n.Titolo, n.IDCategoria, n.Data, n.Descrizione, N AS Notizia FROM notizie AS n, notizie_legami AS nl WHERE n.IDNotizia=nl.IDNotizia AND n.Online='S' AND (n.Pubblicail='S' OR n.Pubblicail IS NULL) AND ((n.Titolo LIKE 'S' OR n.Sottotitolo LIKE 'S' OR n.Descrizione LIKE 'S' OR n.Notizia LIKE 'S') AND (n.Titolo LIKE 'S' OR n.Sottotitolo LIKE 'S' OR n.Descrizione LIKE 'S' OR n.Notizia LIKE 'S')) GROUP BY nl.IDCollegamento) UNION (SELECT IDNews, Titolo, IDCategoria, Data, News, N AS Notizia FROM news WHERE id_ext!='S' AND ((Titolo LIKE 'S' OR News LIKE 'S') AND (Titolo LIKE 'S' OR News LIKE 'S'))) ORDER BY Data DESC LIMIT N
Count: 1 Time=1.21s (1s) Lock=0.00s (0s) Rows=34.0 (34), balkanwe_wp[balkanwe_wp]@localhost
SELECT n.IDNotizia FROM notizie AS n, notizie_legami AS nl WHERE n.IDNotizia=nl.IDNotizia AND n.Online='S' AND (n.Pubblicail='S' OR n.Pubblicail IS NULL) AND ((n.Titolo LIKE 'S' OR n.Sottotitolo LIKE 'S' OR n.Descrizione LIKE 'S' OR n.Notizia LIKE 'S') AND (n.Titolo LIKE 'S' OR n.Sottotitolo LIKE 'S' OR n.Descrizione LIKE 'S' OR n.Notizia LIKE 'S')) GROUP BY nl.IDCollegamento
Count: 4 Time=1.82s (7s) Lock=0.01s (0s) Rows=199.8 (799), balkanwe_wp[balkanwe_wp]@localhost
SELECT n.IDNotizia FROM notizie AS n, notizie_legami AS nl WHERE n.IDNotizia=nl.IDNotizia AND n.Online='S' AND (n.Pubblicail='S' OR n.Pubblicail IS NULL) AND (n.Titolo LIKE 'S' OR n.Sottotitolo LIKE 'S' OR n.Descrizione LIKE 'S' OR n.Notizia like 'S') GROUP BY nl.IDCollegamento
Count: 5 Time=1.52s (7s) Lock=0.00s (0s) Rows=19.4 (97), balkanwe_site[balkanwe_site]@localhost
SELECT ID, post_title, post_type, post_status FROM bwp_posts WHERE (post_title REGEXP 'S' OR post_content REGEXP 'S') AND post_type = 'S' AND ID != N AND post_status NOT IN ('S', 'S') ORDER BY post_date DESC LIMIT N
您可以通過運行以下命令檢查最慢的查詢,
mysqldumpslow -s -t 5的slow.log
這將顯示前5個慢查詢。
不是答案 – gpweb 2014-11-25 12:23:39
@gpweb,也許我誤解了你的問題。我告訴過你哪個查詢對大多數響應時間負責,並且我給了你自己產生相同報告的資源鏈接。我該如何改進這個答案?你在找什麼? – 2014-11-25 15:12:50
我需要了解如何修改它,請如果你有時間來解釋如何處理php文件,使用這個查詢來修復它 – gpweb 2014-11-25 16:35:03