事物隔離等級和行日誌格式設定不當導致故障案例

來源:互聯網
上載者:User

最近剛接手個新項目的測試平台採用了spring的事務機制,在使用者認證登入時總是提示認證逾時,於時查看相應的各應用伺服器日誌,發現報了異常:

Binary logging not possible. Message: Transaction level 'READ-COMMITTED' in InnoDB is not safe for binlog mode 'STATEMENT'...

......


前端某台應用伺服器報如下錯:

{"returnNo":0,"listField":[{"userCode":"admin","newPassword":"","sessionKey":"","password":"670b14728ad9902aecba32e22fa4f6bd","ip":"192.168.1.75"}],"returnObject":null,"commondId":"8000"}

java.io.IOException: Server returned HTTP response code: 500 for URL: http://xxxxx/xxxxxx

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1313)


其實通過最上面那條錯誤可以判斷問題出在哪了.由於innodb 和 binlog不相容引起的...MySQL推薦:當設定隔離等級為READ-COMMITED必須設定行日誌格式為ROW,現在MySQL官方也明確說明STATEMENT 這個已經不建議用了!


當前系統的交易隔離等級是: READ-COMMITTED,行日誌格式是:STATEMENT


這裡可以有兩種解決辦法:

一種是提升事物隔離等級為 REPEATABLE-READ,這是MySQL預設的交易隔離等級;

mysql> set global transaction isolation level repeatable read;


一種是保持當前的交易隔離等級,修改行日誌格式為 MIXED 或 ROW.

這裡修改設定檔:

binlog_format = row

#binlog_format = MIXED

重啟服務


有個特別要注意的問題,如果 binlog_format 為 MIXED,而且使用的是預設隔離等級REPEATABLE-READ,那麼會導致主從資料不一致。


參考賀總部落格:http://hcymysql.blog.51cto.com/5223301/1021174


本文出自 “->” 部落格,請務必保留此出處http://opsmysql.blog.51cto.com/2238445/1201544

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.