MySQL主從數據複製問題解決辦法

mysql主從複製,經常會遇到錯誤而導致slave端複製中斷,這個時候一般就需要人工干預,跳過錯誤才能繼續
跳過錯誤有兩種方式:
1.跳過指定數量的事務:
mysql>slave stop;
mysql>set global sql_slave_skip_counter=1;        #跳過一個事務
mysql>slave start

2.修改mysql的配置文件,通過slave_skip_errors參數來跳所有錯誤或指定類型的錯誤
vi /etc/my.cnf
[mysqld]
slave-skip-errors=1062,1053,1146 #跳過指定error no類型的錯誤
#slave-skip-errors=all #跳過所有錯誤

注意:當配置文件裏寫兩行:
slave-skip-errors=1062
slave-skip-errors=1032時,第二個參數會覆蓋第一個參數。所以一定要寫到同一行,並用逗號分隔。

雖然slave會跳過這些錯誤,繼續複製,但是仍會以Warning的形式記錄到錯誤日誌中,如:
160620 10:40:17 [Warning] Slave SQL: Could not execute Write_rows event on table dba.t; Duplicate entry '10' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.000033, end_log_pos 1224, Error_code: 1062
重啓Mysql服務
那些沒有被複制的錯誤數據會輸出到日誌中
如:
 Error_code: 1062
Aug 16 17:44:53 mysql75 mysqld: 2017-08-16T09:44:53.142158Z 2 [Note] Slave SQL for channel '': Could not execute Query event. Detailed error: Duplicate entry '2017-08-14-3002-15616-62' for key 'PRIMARY';, Error_code: 1062
Aug 16 17:44:57 mysql75 mysqld: 2017-08-16T09:44:57.910737Z 2 [Note] Slave SQL for channel '': Could not execute Query event. Detailed error: Duplicate entry '2017-08-14-3002-15626-84' for key 'PRIMARY';, Error_code: 1062
Aug 16 17:44:57 mysql75 mysqld: 2017-08-16T09:44:57.911141Z 2 [Note] Slave SQL for channel '': Could not execute Query event. Detailed error: Duplicate entry '2017-08-14-3002-15626-85' for key 'PRIMARY';, Error_code: 1062
Aug 16 17:44:57 mysql75 mysqld: 2017-08-16T09:44:57.911918Z 2 [Note] Slave SQL for channel '': Could not execute Query event. Detailed error: Duplicate entry '2017-08-14-3002-15626-87' for key 'PRIMARY';, Error_code: 1062
Aug 16 17:44:57 mysql75 mysqld: 2017-08-16T09:44:57.912676Z 2 [Note] Slave SQL for channel '': Could not execute Query event. Detailed error: Duplicate entry '2017-08-14-3002-15626-88' for key 'PRIMARY';, Error_code: 1062
Aug 16 17:44:57 mysql75 mysqld: 2017-08-16T09:44:57.913248Z 2 [Note] Slave SQL for channel '': Could not execute Query event. Detailed error: Duplicate entry '2017-08-14-3002-15626-89' for key 'PRIMARY';, Error_code: 1062
Aug 16 17:44:57 mysql75 mysqld: 2017-08-16T09:44:57.913808Z 2 [Note] Slave SQL for channel '': Could not execute Query event. Detailed error: Duplicate entry '2017-08-14-3002-15626-90' for key 'PRIMARY';, Error_code: 1062
Aug 16 17:44:57 mysql75 mysqld: 2017-08-16T09:44:57.914573Z 2 [Note] Slave SQL for channel '': Could not execute Query event. Detailed error: Duplicate entry '2017-08-14-3002-15626-91' for key 'PRIMARY';, Error_code: 1062
Aug 16 17:46:18 mysql75 mysqld: 2017-08-16T09:46:18.933328Z 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 15293ms. The settings might not be optimal. (flushed=4427 and evicted=0, during the time.)
Aug 16 17:48:48 mysql75 mysqld: 2017-08-16T09:48:48.759770Z 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 4020ms. The settings might not be optimal. (flushed=4850 and evicted=0, during the time.)
Aug 16 17:49:30 mysql75 mysqld: 2017-08-16T09:49:30.383725Z 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 4139ms. The settings might not be optimal. (flushed=4984 and evicted=0, during the time.)

發生這種情況,一般是主機斷電引起的!!

發佈了40 篇原創文章 · 獲贊 3 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章