国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

MySQL 5.6主從報錯的實戰記錄

瀏覽:28日期:2023-10-05 09:44:13
1. 問題現象

版本:MySQL 5.6,采用傳統 binlog file & pos 方式配置的主從復制結構。

MySQL 5.6主從報錯的實戰記錄

實例重啟后,主從復制報錯如上圖所示。

2. 錯誤含義

錯誤分為2部分。

第一部分

Client requested master to start replication from position > file size; the first event ’mysql-bin.000398’ at 163800795,the last event read from ’./mysql-binlog.000398’ at 4,the last byte read from ’./mysql-bin.000398’ at 4’

第一部分

這部分來源于主庫的DUMP線程函數

mysql_binlog_send ->sender.run() ->Binlog_sender::init ->Binlog_sender::check_start_file if ((file= open_binlog_file(&cache, m_linfo.log_file_name, &errmsg)) < 0) { set_fatal_error(errmsg); return 1; } size= my_b_filelength(&cache); end_io_cache(&cache); mysql_file_close(file, MYF(MY_WME)); if (m_start_pos > size) { set_fatal_error('Client requested master to start replication from ' 'position > file size'); return 1; }

關鍵就是m_start_pos和size兩個值,其中m_start_pos來源于從庫需要讀取的位點。而size則是本binlog文件的大小,那么很容易理解如果io線程需要的pos點比本binlog文件的大小還要大,那么自然不對。

第二部分

這部分也來源于DUMP線程

mysql_binlog_send ->sender.run() ->Binlog_sender::init ->while (!has_error() && !m_thd->killed) #如果正常這里開始循環讀取binlog event,如果前面出錯則直接繼續后面邏輯 #如果有讀取錯誤則報錯 my_snprintf(error_text, sizeof(error_text), '%s; the first event ’%s’ at %lld, ' 'the last event read from ’%s’ at %lld, ' 'the last byte read from ’%s’ at %lld.', m_errmsg, m_start_file, m_start_pos, m_last_file, m_last_pos, log_file, my_b_tell(&log_cache));

這里我們主要看看m_start_pos和m_last_pos,實際上m_start_pos就是和前面報錯一致的來自從庫需要讀取的位點信息,而m_last_pos來自dump線程,就是最后讀取的位置,顯然這里一次都沒有讀取,因此位置為最開始的pos 4。

3. 可能的原因

分析后覺得最有可能原因應該和sync_binlog 有關。

如果我們沒有設置為1,那么可能os cache沒有刷盤,如果主庫服務器直接crash重啟很容易就遇到這種問題。

稍微google查詢了一下發現很大部分出現這種錯誤都是由于服務器crash且sync_binlog 沒設置為 1導致的。

這也證明我們的說法。

最后查看問題數據庫的主庫確實沒有設置為雙1。

那么通過這個小案例,我們已經更加深刻體會到設置雙1的重要性。

總結

到此這篇關于MySQL 5.6主從報錯的文章就介紹到這了,更多相關MySQL5.6主從報錯內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: MySQL 數據庫
相關文章:
主站蜘蛛池模板: 龙陵县| 棋牌| 南京市| 海盐县| 乐安县| 岳阳市| 札达县| 金秀| 乌兰浩特市| 宁波市| 井冈山市| 兴海县| 安西县| 甘南县| 万山特区| 惠来县| 芜湖市| 通州区| 开化县| 军事| 焦作市| 徐水县| 翁源县| 山阴县| 丹东市| 中宁县| 岫岩| 彰化市| 海晏县| 泰来县| 来安县| 怀集县| 陵川县| 汽车| 新野县| 漳浦县| 武邑县| 大冶市| 察隅县| 鹿邑县| 招远市|