国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

逐步分析MySQL從庫com_insert無變化的原因

2020-01-18 23:17:13
字體:
來源:轉載
供稿:網友

大家都知道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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桑植县| 平谷区| 信宜市| 樟树市| 临夏市| 花莲县| 化州市| 新竹县| 邵武市| 贞丰县| 三门县| 墨江| 葵青区| 商都县| 玛曲县| 和平县| 伊川县| 海伦市| 化德县| 横峰县| 全州县| 兴安县| 德令哈市| 万载县| 岳阳县| 锡林郭勒盟| 舞阳县| 游戏| 营口市| 东台市| 突泉县| 革吉县| 察雅县| 民乐县| 泸州市| 龙岩市| 枞阳县| 隆林| 阿坝县| 甘南县| 新龙县|