mysql从库执行delete停止_MySQL主库大表执行delete语句,Ctrl+C具体发生了什么分析...
MySQL主庫大表執行delete語句,Ctrl+C具體發生了什么分析
1、查看表結構
localhost.qt>show create table doctor_stats_backup\G
*************************** 1. row ***************************
Table: doctor_stats_backup
Create Table: CREATE TABLE `doctor_stats_backup` (
`id` int(10) unsigned NOT NULL DEFAULT '0',
`uid` int(10) unsigned NOT NULL DEFAULT '0',
`typeact` tinyint(3) unsigned NOT NULL DEFAULT '0',
`flag` tinyint(3) unsigned NOT NULL DEFAULT '1',
`intime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`qid` int(10) unsigned NOT NULL DEFAULT '0',
`rid` int(10) unsigned NOT NULL DEFAULT '0',
KEY `intime` (`intime`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
2、查看行數
localhost.qt>select count(*) from doctor_stats_backup;
+-----------+
| count(*) |
+-----------+
| 174541079 |
+-----------+
1 row in set (0.00 sec)
3、在主庫上執行delete然后CTRL+C
4、從庫收到告警,主從已經中斷
5、再分別查看主從doctor_stats_backup的行數
主庫
從庫
可以見主庫上已經刪除5499096行,而從庫并沒有進行刪除操作;推斷是主庫的binglog沒有傳遞到從庫,造成了主從不一致,接下來分析下binlog查看原因。
6.查看binlog
主庫
可以看到,mysql對delete操作開啟了一個事務
從庫
Binlog里并沒有看到delte操作;從庫開啟了log-slave-update,只有binglog回放后才會記錄到binlog,現在查看從庫的relay-log
在從庫的relay-log里可以看到delete操作,但是為什么會不執行呢?
參照http://itlab.idcquan.com/linux/MYSQL/918702_3.html對CTRL+C源碼的分析,MySQL客戶端捕獲信號后,向服務器端發送KILL /*!50000 QUERY */ 命令并執行,從而將Query處理kill。
DuringUPDATEorDELETEoperations, the kill flag is checked after each block read and after each updated or deleted row. If the kill flag is set, the statement is aborted. If you are not using transactions, the changes are not rolled back.
對于update、delete數據更新操作,CTRL+C會將執行的操作標記為KILLED狀態,然后執行回滾操作。但是如果沒有開啟事務或者引擎不支持事務,則不會執行回滾。
這樣就可以理解了,主庫delete過程中執行CTRL+C操作,kill掉了query id而需要進行回滾;由于doctor_stats_backup表是MyISAM表,不能進行回滾--則mysql把binlog打上標記,從庫接收主庫傳過來有標記的binlog也就不執行了,所以從庫的relaylog里有delete語句而binlog里沒有。
至于是什么標記呢?我們需要動手做實驗找找了:
再次delete一次數據,不執行CTRL+C,觀察binglog:
對比發現執行了CTRL+C的delete操作的binlog里包含error_code=1317,而不執行CTRL+C的delete操作的binlog里包含error_code=0;答案出現了正是error_code=1317告訴從庫不執行這條binlog,而彈出了
錯誤。
下面我們把doctor_stats_backup表的引擎修改為innodb,再重復上面的實驗:
Innodb可以正常的回滾,binlog里不留下一點痕跡,也就不存在主從不同步了。
總結
以上是生活随笔為你收集整理的mysql从库执行delete停止_MySQL主库大表执行delete语句,Ctrl+C具体发生了什么分析...的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 2023年iOS将要推出哪几项新功能20
- 下一篇: 苹果iPhone14 拍照太亮怎么办
