慢慢剖析MySQL從庫com_insert無變更的緣由。本站提示廣大學習愛好者:(慢慢剖析MySQL從庫com_insert無變更的緣由)文章只能為提供參考,不一定能成為您想要的結果。以下是慢慢剖析MySQL從庫com_insert無變更的緣由正文
年夜家都曉得com_insert等com_xxx參數可以用來監控數據庫實例的拜訪量,也就是我們常說的QPS。而且基於MySQL的復制道理,一切主庫履行的操作都邑在從庫重放一遍包管數據分歧,那末主庫的com_insert和從庫的com_insert實際上應當是相等的。
以下面顯示,第二列代表主庫,第三列代表從庫:
com_select 22 1138
com_update 36 37
com_insert 133 135
com_delete 0 0
qcache_hits 0 0
Com_replace 0 0
Connections 13 24
然則我們看別的一個營業:
com_select 0 95
com_update 0 0
com_insert 92 0
com_delete 20 0
qcache_hits 0 6
Com_replace 0 0
Connections 0 6
我們可以很顯著的看出來,主庫有92個寫,然則從庫0個寫,這是為何呢?
這2個營業獨一的差別就是binlog_format的設置紛歧樣。
第一個營業
show global variables like '%binlog_format%';
+---------------+-----------+
| Variable_name | Value |
+---------------+-----------+
| binlog_format | STATEMENT |
+---------------+-----------+
第二個營業
show global variables like '%binlog_format%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| binlog_format | ROW |
+---------------+-------+
我們來看下com_xxx的官方文檔界說:
The Com_xxx statement counter variables indicate the number of times each xxx statement has been executed. There is one status variable for each type of statement. For example, Com_delete and Com_update count DELETE and UPDATE statements, respectively. Com_delete_multi and Com_update_multi are similar but apply to DELETE and UPDATE statements that use multiple-table syntax.
從上述文檔,我們只能看到com_xxx是若何運作的,然則其實不能說明為何應用RBR以後com_insert就不變更了。
接上去我們聯合上面這段文檔來一路看看。
You cannot examine the logs to see what statements were executed, nor can you see on the slave what statements were received from the master and executed. However, you can see what data was changed using mysqlbinlog with the options --base64-output=DECODE-ROWS and --verbose.
這2段話聯合來看,緣由應當是如許的:
1、主庫上吸收的是statement的語句,所以com_insert相符觸發前提,會跟著營業增長。
2、而從庫是拿到主庫的binlog後重放更新數據,然則主庫的日記格局是row format,這就招致了binlog中記載的不是statement語句,而是data的變更記載。
3、如許從庫固然仍然能停止更新記載,然則沒法解析出來這些data變更是一條statement語句招致的照樣多條statment語句招致,所以就不在更新com_insert這個statment counter了。
根本上推論相符實際情形,然則沒有code證實,比擬遺憾。
別的,假如我們沒法經由過程com_insert來監控從庫的寫入情形,那末我們應當監控誰人status呢?
小我建議關於row格局的實例,經由過程監控innodb_rows_inserted來監控寫入情形。
show global status like 'innodb_rows_inserted';
+----------------------+------------+
| Variable_name | Value |
+----------------------+------------+
| Innodb_rows_inserted | 2666049650 |
+----------------------+------------+
附:(兩個文檔的官方文檔鏈接)
http://dev.mysql.com/doc/refman/5.6/en/server-status-variables.html#statvar_Com_xxx
http://dev.mysql.com/doc/refman/5.5/en/replication-sbr-rbr.html