MySQL:Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEM
1:错误日志大量错误
15060214:40:02[Warning]UnsafestatementwrittentothebinarylogusingstatementformatsinceBINLOG_FORMAT=STATEMENT.INSERT...SELECT...ONDUPLICATEKEYUPDATEisunsafebecausetheorderinwhichrowsareretrievedbytheSELECTdetermineswhich(ifany)rowsareupdated.Thisordercannotbepredictedandmaydifferonmasterandtheslave.Statement:INSERTINTOtab_name
2:原因:
查了下原因,tab_name这个表上有2个唯一键。则使用INSERT…ONDUPLICATEKEYUPDATE,且当前数据库binlog_format是statement格式,这种sql语句就会报unsafe。
官方手册:
INSERT…ONDUPLICATEKEYUPDATEstatementsontableswithmultipleprimaryoruniquekeys.Whenexecutedagainstatablethatcontainsmorethanoneprimaryoruniquekey,thisstatementisconsideredunsafe,beingsensitivetotheorderinwhichthestorageenginechecksthekeys,whichisnotdeterministic,andonwhichthechoiceofrowsupdatedbytheMySQLServerdepends.
解决方法:
把binlog_format设置为ROW或者STATEMENT或者修改SQL。
一般情况下就是mysql配置问题,大家可以参考这篇文章:https://www.nhooo.com/article/84357.htm