MySQL監控效能的一些方法總結

來源:互聯網
上載者:User

MySQL監控效能的一些方法總結

---首先, Oracle中的邏輯讀對應物理讀的概念,是在利用資料緩衝區的技術上,對資料訪問次數的計數分類。
---物理讀,真正有IO;邏輯讀,是從緩衝區讀到資料,可以考察緩衝區的命中率,但只是某個具體對象在緩衝區中的命中率。
---所以,使用資料緩衝區技術的,都可以有類似的方式。但是,這僅是從IO的角度去衡量資料庫的效能的。即不完全可靠。
---其次,MySQL提供了一些方式,用以考察IO的使用方式。
---MySQL方式1:區分“索引讀”還是“隨機讀”。這種情況,不從緩衝區的角度出發,是從單表掃描資料的方式的角度出發的。
---所以,可以採用如下方式輔助判斷:
mysql> show status like 'handler_read%';
+-----------------------+-------+
| Variable_name        | Value |
+-----------------------+-------+
| Handler_read_first    | 0    |
| Handler_read_key      | 2    |
| Handler_read_last    | 0    |
| Handler_read_next    | 0    |
| Handler_read_prev    | 0    |
| Handler_read_rnd      | 0    |
| Handler_read_rnd_next | 0    |
+-----------------------+-------+
7 rows in set (0.00 sec)
---MySQL方式2:通過狀態變數瞭解伺服器整體狀況
---通過show status和應用特點瞭解各種sql的執行頻率
---通過show status可以提供伺服器狀態資訊,如以下幾個參數對MyISAM和Innodb儲存引擎都計數:
1、com_select:執行select操作的計數,一次查詢只累加1;
2、com_insert:執行insert操作的次數,對於批量插入的insert操作,只累加一次;
3、com_update:執行update操作的次數;
4、com_delete:執行delete操作的次數;
---以下幾個參數是針對Innodb儲存引擎計數的,累加的演算法也略有不同:
1、Innodb_rows_read:查詢返回的行數,不僅是select操作,delete和update也會觸發對元組的讀操作;
2、Innodb_rows_inserted:執行insert操作插入的行數;
3、Innodb_rows_updated:執行update操作更新的行數;
4、Innodb_rows_deleted:執行delete 操作刪除的行數;
通過以上幾個參數,使用show status 命令查看參數值,就可以很容易瞭解當前資料庫的應用是以插入更新為主還是查詢操作為主,對於更新操作的計數,是對執行次數的計數,不論成功提交還是復原都會累加。
對於事務型的應用,可以通過com_commit和com_rollback可以瞭解事務提交和復原的情況,對於復原操作非常頻繁的資料庫,可能意味著存在應用編寫問題。
---MySQL方式3:通過PFS(Performance Schema)瞭解伺服器整體狀況/IO狀況
1、The MySQL Performance Schema is a feature for monitoring MySQL Server execution at a low level.
2、The Performance Schema monitors server events. An “event” is anything the server does that takes time and has been instrumented so that timing information can be collected. In general, an event could be a function call, a wait for the operating system, a stage of an SQL statement execution such as parsing or sorting, or an entire statement or group of statements. Currently, event collection provides access to information about synchronization calls (such as for mutexes) file and table I/O, table locks, and so forth for the server and for several storage engines.
3、這個功能很強大, 請大家注意掌握. 內容多我們不一一說明,可以參考官方手冊的performance-schema.htm檔案. 他必定要成為MySQL監控的主流.

--------------------------------------分割線 --------------------------------------

Ubuntu 14.04下安裝MySQL

《MySQL權威指南(原書第2版)》清晰中文掃描版 PDF

Ubuntu 14.04 LTS 安裝 LNMP Nginx\PHP5 (PHP-FPM)\MySQL

Ubuntu 14.04下搭建MySQL主從伺服器

Ubuntu 12.04 LTS 構建高可用分布式 MySQL 叢集

Ubuntu 12.04下原始碼安裝MySQL5.6以及Python-MySQLdb

MySQL-5.5.38通用二進位安裝

--------------------------------------分割線 --------------------------------------

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.