日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

MySql 缓存查询原理与缓存监控 和 索引监控

發布時間:2023/12/10 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MySql 缓存查询原理与缓存监控 和 索引监控 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

MySql緩存查詢原理與緩存監控 And 索引監控

by:授客 QQ1033553122

?

查詢緩存

1.查詢緩存操作原理

mysql執行查詢語句之前,把查詢語句同查詢緩存中的語句進行比較,且是按字節比較,僅完全一致才被認為相同。如下,這兩條語句被視為不同的查詢

SELECT * FROM tb1_name

Select * from tb1_name

?

1)不同數據庫、不同協議版本,或字符集不同的查詢被視為不同的查詢并單獨緩存。

2)以下兩種類型的查詢不被緩存

a.預處理語句

b.嵌套查詢的子查詢

3)從查詢緩存抓取查詢結果前,mysql檢查用戶對查詢涉及的所有數據庫和表是否有查詢權限,如果沒有則不使用緩存查詢結果。

4)如果從緩存查詢返回一個查詢結果,服務器遞增Qcache_hits狀態變量,而不是Com_select

5)如果表改變,所有使用了該表的緩存查詢變成不合法,從緩存移除。表可能被多種類型的語句改變,比如INSERT, UPDATE, DELETE, TRUNCATE TABLE, ALTER TABLE, DROP TABLE, DROP DATABASE.

?

參考連接:

http://dev.mysql.com/doc/refman/4.1/en/query-cache-operation.html

?

2.查看是否開啟了緩存查詢

SHOW VARIABLES LIKE 'have_query_cache';

?

3.從查詢緩存中移除所有查詢緩存

RESET QUERY CACHE;

?

4.查詢緩存性能監控

SHOW STATUS LIKE 'Qcache%'

輸出說明:

Qcache_free_blocks查詢緩存中的空閑內存塊

Qcache_free_memory查詢緩存的空閑內存數量

Qcache_hits查詢緩存命中數量

Qcache_inserts添加到查詢緩存的查詢的數量(不是表示沒被緩存而進行的讀,而是緩存失效而進行的讀)

Qcache_lowmen_prunes因內存太低,從緩存查詢中刪除的查詢的數量

Qcache_not_chached:未緩存查詢的數量(未被緩存、因為querey_cache_type設置沒被緩存)

Qcache_queries_in_cache緩存查詢中注冊的查詢的數量

Qcache_total_blocks查詢緩存中的內存塊總數

?

SELECT查詢總數:

Com_select+Qcache_hits+ 解析錯誤的查詢數(queries with errors found by parser)

其中,Com_select表示未命中緩存數,Qcache_hits表示緩存命中數

Com_select計算公式:

Qcache_inserts+Qcache_not_cached+權限檢查錯誤數(queries with errors found during the column-privileges check)

?

索引監控

SHOW STATUS LIKE 'handler_read%';

輸出說明:

Handler_read_first

The number of times the first entry in an index was read. If this value is high, it suggests that the server is doing a lot of full index scans; for example, SELECT col1 FROM foo, assuming that col1 is indexed

索引中的第一項(the first entry in an index)被讀取的次數,如果該值很高,那表明服務器正在執行很多全索引掃描,例如 SELECT col1 FROM foo, 假設col1上建立了索引

?

Handler_read_key

The number of requests to read a row based on a key. If this value is high, it is a good indication that your tables are properly indexed for your queries.

基于某個鍵讀取一行的請求次數。如果該值很高,那很好的說明了,對于執行的請求,表采用了適當的索引。

?

Handler_read_next

The number of requests to read the next row in key order. This value is incremented if you are querying an index column with a range constraint or if you are doing an index scan.

根據鍵順序,讀取下一行的請求次數。如果你正在查詢一個帶一系列約束的索引列或者正在執行索引掃描時,該值會增加

?

Handler_read_prev

The number of requests to read the previous row in key order. This read method is mainly used to optimize ORDER BY ... DESC

根據鍵的順序,請求讀取前一行的次數。該讀取方法主要用于優化 ORDER BY ... DESC

?

Handler_read_rnd

The number of requests to read a row based on a fixed position. This value is high if you are doing a lot of queries that require sorting of the result. You probably have a lot of queries that require MySQL to scan entire tables or you have joins that do not use keys properly.

在固定位置讀取一行的請求次數。該值如果很高,那么說明正在執行許多要求對結果集排序的查詢。可能在執行有許多要求全表掃描的查詢,或沒使用適合鍵的聯合查詢。

Handler_read_rnd_next

The number of requests to read the next row in the data file. This value is high if you are doing a lot of table scans. Generally this suggests that your tables are not properly indexed or that your queries are not written to take advantage of the indexes you have.

讀取數據文件中下一行的請求次數。該值很高,表明正在執行很多全表掃描。通常表明表沒使用適當的索引或者查詢請求沒利用現成的索引。

參考連接:

http://dev.mysql.com/doc/refman/5.7/en/dynindex-statvar.html#statvar-index-H

?

參考連接:

http://dev.mysql.com/doc/refman/4.1/en/server-status-variables.html

http://dev.mysql.com/doc/refman/4.1/en/query-cache-status-and-maintenance.html

?


轉載于:https://www.cnblogs.com/shouke/p/10157911.html

總結

以上是生活随笔為你收集整理的MySql 缓存查询原理与缓存监控 和 索引监控的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。