mysql-error 1236

來源:互聯網
上載者:User

標籤:mysql   slave   1236   1236 error   1236錯誤   

今天其中一台遊戲伺服器的資料庫mysql master當機, 系統變為唯讀模式,重啟後進入安全模式,執行fsck後恢複正常。伺服器起來之後mysql啟動正常,但一台slave卻一直出現同步錯誤。

登入後查看,發現以下錯誤:

mysql> show slave status\G*************************** 1. row ***************************               Slave_IO_State:                   Master_Host: 10.90.13.238                  Master_User: slave                  Master_Port: 3306                Connect_Retry: 60              Master_Log_File: mysql-bin.000949          Read_Master_Log_Pos: 277562491               Relay_Log_File: mysql-relay-bin.001616                Relay_Log_Pos: 277562637        Relay_Master_Log_File: mysql-bin.000949             Slave_IO_Running: No            Slave_SQL_Running: Yes              Replicate_Do_DB:           Replicate_Ignore_DB:            Replicate_Do_Table:        Replicate_Ignore_Table:       Replicate_Wild_Do_Table:   Replicate_Wild_Ignore_Table:                    Last_Errno: 0                   Last_Error:                  Skip_Counter: 1          Exec_Master_Log_Pos: 277562491              Relay_Log_Space: 277562836              Until_Condition: None               Until_Log_File:                 Until_Log_Pos: 0           Master_SSL_Allowed: No           Master_SSL_CA_File:            Master_SSL_CA_Path:               Master_SSL_Cert:             Master_SSL_Cipher:                Master_SSL_Key:         Seconds_Behind_Master: NULLMaster_SSL_Verify_Server_Cert: No                Last_IO_Errno: 1236                Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: ‘Client requested master to start replication from impossible position; the first event ‘mysql-bin.000949‘ at 277562491, the last event read from ‘./mysql-bin.000949‘ at 4, the last byte read from ‘./mysql-bin.000949‘ at 4.‘               Last_SQL_Errno: 0               Last_SQL_Error:   Replicate_Ignore_Server_Ids:              Master_Server_Id: 41 row in set (0.00 sec)

錯誤為:

Got fatal error 1236 from master when reading data from binary log: ‘Client requested master to start replication from impossible position; the first event ‘mysql-bin.000949‘ at 277562491, the last event read from ‘./mysql-bin.000949‘ at 4, the last byte read from ‘./mysql-bin.000949‘ at 4.‘


這個錯誤之前也遇到過,但沒有具體記錄下來,於是網上找資料。

參考了這幾個資料:

http://www.brianklug.com/w/page/15052161/MySQL%20Error%3A%20Client%20requested%20master%20to%20start%20replication%20from%20impossible%20position

http://blog.ez2learn.com/2011/11/28/mysql-1236-solution/

http://blog.longwin.com.tw/2013/09/mysql-replication-error-1236-fix-2013/


出現這樣的錯誤原因很簡單,原本的slave在master當機前一直在執行同步的動作,當master當機重啟mysql恢複之後,會重新開一個新的binlog繼續寫,但slave不知道發生了這件事,所以還在問上次同步的那個binlog檔案和讀到得那個位置。

要確定這個情況,我執行了如下的操作:

1. 檢查master的位置

mysql> show master status\G*************************** 1. row ***************************            File: mysql-bin.000950        Position: 336492640    Binlog_Do_DB: Binlog_Ignore_DB: 1 row in set (0.00 sec)mysql> show master status;


2. 檢查master上binlog的大小和最新的修改時間:

[[email protected] ~]# ll /data/mysql/mysql-bin.*-rw-rw---- 1 mysql mysql 1073742473 Nov 17 10:38 /data/mysql/mysql-bin.000944-rw-rw---- 1 mysql mysql 1073742022 Nov 18 12:44 /data/mysql/mysql-bin.000945-rw-rw---- 1 mysql mysql 1073745576 Nov 19 15:31 /data/mysql/mysql-bin.000946-rw-rw---- 1 mysql mysql 1073745324 Nov 21 05:03 /data/mysql/mysql-bin.000947-rw-rw---- 1 mysql mysql 1073742027 Nov 22 16:09 /data/mysql/mysql-bin.000948-rw-rw---- 1 mysql mysql  277553623 Nov 23 05:07 /data/mysql/mysql-bin.000949-rw-rw---- 1 mysql mysql  337157571 Nov 23 18:04 /data/mysql/mysql-bin.000950-rw-rw---- 1 mysql mysql        133 Nov 23 08:06 /data/mysql/mysql-bin.index
[[email protected] ~]# du /data/mysql/mysql-bin.* -sh1.1G    /data/mysql/mysql-bin.0009441.1G    /data/mysql/mysql-bin.0009451.1G    /data/mysql/mysql-bin.0009461.1G    /data/mysql/mysql-bin.0009471.1G    /data/mysql/mysql-bin.000948265M    /data/mysql/mysql-bin.000949323M    /data/mysql/mysql-bin.0009504.0K    /data/mysql/mysql-bin.index

從這裡可以發現,000949是mysql在系統崩潰的時候最後寫過的檔案,在恢複之後重建立立了一個新的

000950,從時間和大小的條件可以判斷,正常情況下mysql-bin.000949應該會寫到1.1G的時候才會重建立立新的檔案繼續寫,現在的情況是伺服器宕機導致binlog crash了,所以mysql啟動後會重建立立一個新的binlog檔案。


3. 在slave上執行如下命令:

mysql> stop slave    -> ;Query OK, 0 rows affected (0.00 sec)mysql> change master to master_host=‘10.90.13.238‘, master_user=‘slave‘ ,MASTER_PASSWORD=‘‘,MASTER_LOG_FILE=‘mysql-bin.000950‘,MASTER_LOG_POS=4;Query OK, 0 rows affected (0.09 sec)

就是在mysql上重新指定新的binlog和它的初始位置。然後啟動slave:

mysql> start slave;

觀察slave啟動正常了

mysql> show slave status\G*************************** 1. row ***************************               Slave_IO_State: Waiting for master to send event                  Master_Host: 10.90.13.238                  Master_User: slave                  Master_Port: 3306                Connect_Retry: 60              Master_Log_File: mysql-bin.000950          Read_Master_Log_Pos: 336968550               Relay_Log_File: mysql-relay-bin.000002                Relay_Log_Pos: 52752780        Relay_Master_Log_File: mysql-bin.000950             Slave_IO_Running: Yes            Slave_SQL_Running: Yes              Replicate_Do_DB:           Replicate_Ignore_DB:            Replicate_Do_Table:        Replicate_Ignore_Table:       Replicate_Wild_Do_Table:   Replicate_Wild_Ignore_Table:                    Last_Errno: 0                   Last_Error:                  Skip_Counter: 0          Exec_Master_Log_Pos: 52752634              Relay_Log_Space: 336968852              Until_Condition: None               Until_Log_File:                 Until_Log_Pos: 0           Master_SSL_Allowed: No           Master_SSL_CA_File:            Master_SSL_CA_Path:               Master_SSL_Cert:             Master_SSL_Cipher:                Master_SSL_Key:         Seconds_Behind_Master: 31164Master_SSL_Verify_Server_Cert: No                Last_IO_Errno: 0                Last_IO_Error:                Last_SQL_Errno: 0               Last_SQL_Error:   Replicate_Ignore_Server_Ids:              Master_Server_Id: 41 row in set (0.00 sec)mysql>



本文出自 “安家圈子交流學習” 部落格,請務必保留此出處http://brucetam.blog.51cto.com/1863614/1581815

mysql-error 1236

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.