昨天修改一個表的字段,發現主從複制同步失效了,但同步程序沒有出錯,mysql日志也沒有出錯,仔細查找了一下原因,發現是新增的自增主鍵字段的起始值在主從庫上不一緻,導緻按主鍵更新資料時無法在從庫找到對應記錄。事情經過如下:
表table1(主庫為innodb類型,從庫為MyISAM類型),有一自增主鍵pid,現将pid改成非自增,非主鍵,另外增加一自增主鍵。
alter table table1 modify pid int not null;
alter talbe table1 drop primary key;
alter table table1 add aid int not null auto_increment primary key first;
結果主庫上表table1的auto_increment屬性自動沒有了,預設重新從1開始,但從庫上表table1的auto_increment屬性還有,還是以前pid的最大值。
奇怪的是我把從庫也改成innodb就沒有這個問題了,懷疑是mysql的bug,在此記錄一下,以後要注意了。