MySQL數(shù)據(jù)庫(kù)經(jīng)典錯(cuò)誤二 Last_SQL_Errno: 1062 (從庫(kù)與主庫(kù)數(shù)據(jù)沖突)
2018-11-08 20:12:49
16700
MySQL數(shù)據(jù)庫(kù)經(jīng)典錯(cuò)誤二 Last_SQL_Errno: 1062 (從庫(kù)與主庫(kù)數(shù)據(jù)沖突)
案例二
主從復(fù)制報(bào)錯(cuò)類型
Last_SQL_Errno: 1062 (從庫(kù)與主庫(kù)數(shù)據(jù)沖突)
Last_Errno: 1062
Last_Error: Could not execute Write_rows event on table test.t;
Duplicate entry ‘4’ for key ‘PRIMARY’,
Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY;
the event’s master log mysql-bin.000014, end_log_pos 1505
針對(duì)這個(gè)報(bào)錯(cuò),我們首先要考慮是不是在從庫(kù)中誤操作導(dǎo)致的。結(jié)果發(fā)現(xiàn),我們?cè)趶膸?kù)中進(jìn)行了一條針對(duì)有主鍵表的SQL語(yǔ)句的插入,導(dǎo)致主庫(kù)再插入相同 sql 的時(shí)候,主從狀態(tài)出現(xiàn)異常。發(fā)生主鍵沖突的報(bào)錯(cuò)。
解決方法:在確保主從數(shù)據(jù)一致性的前提下,可以在從庫(kù)進(jìn)行錯(cuò)誤跳過(guò)。一般使用 percona-toolkit 中的 pt-slave-restart 進(jìn)行。
在從庫(kù)完成如下操作:
[root@zs bin]# ./pt-slave-restart -uroot -proot123
2017-07-20T14:05:30 p=…,u=root node4-relay-bin.000002 1506 1062
之后最好在從庫(kù)中開(kāi)啟 read_only 參數(shù),禁止在從庫(kù)進(jìn)行寫入操作。
會(huì)員登錄
賬號(hào)登錄還沒(méi)有賬號(hào)?立即注冊(cè)