0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

mysql5.5でbinlog_formatによってはslave重複エラーが出た

Last updated at Posted at 2019-09-09

mysql5.5でbinlog_format=mixedでslaveがDuplicateで止まるエラーが出たので備忘録を。

まあ、MyISAMからInnoDBにしたいのでパラメータどうすればいいのか聞かれたので色々オススメしたなかの一つに、バイナリログのサイズ削れるしディスク圧迫抑えられそうだしいいかなーということでbinlog_formatをrowからmixedに変えたのがあったんですが、スレーブがどうあっても開始できなくて開始直後にエラーで止まった。
その時に出たエラーが以下。

[ERROR] Slave SQL: Error 'Cannot add or update a child row: a foreign key constraint fails
[ERROR] Slave SQL for channel '': Error 'Duplicate entry '' for key 'PRIMARY'' on query.

検索したら以下のバグがヒットして再現手順にInnoDB+SBRと書いてありました。
https://bugs.mysql.com/bug.php?id=41754

SBRじゃないけどmixedだと似た動きするときもある。
以下スライドによると整合性重視ならrowがいい(ただしPrimaryキーないとログの量が多くなって詰むようだ)
https://www.slideshare.net/yoku0825/mysql-86831302

まとめるとbinlog_format=rowに戻したらslave開始できました。

ついでに言うと、
5.5までだと、perconaサーバはクラッシュセーフなパラメータがあるようです。
https://www.percona.com/blog/2013/07/15/crash-resistant-replication-how-to-avoid-mysql-replication-errors/

5.6以降であれば以下のパラメータでクラッシュセーフreplicationできるような話を聞いた記憶が。

master-info-repository=TABLE
relay-log-info-repository=TABLE
relay_log_recovery=ON

最初はDuplicate entryならskipでもいいのではという話でしたが、開始位置が間違ってたわけでもなくスキップしてもまた止まってたし、
Skipした場合トランザクションのかかわりのあるものがまとめてスキップされかねないとの情報もありました。
https://yakst.com/ja/posts/14

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?