環境
tomcat 6.x
jdk 1.6
mysql5.5
異常
執行jdbc查詢時拋出異常:
Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.
原因及解決方案
This is required by MySQL:
Statement based binlogging does not work in isolation level
READ UNCOMMITTED and READ COMMITTED since the necessary
locks cannot be taken.
根據tomcat拋異常,提示是事務級別在read committed和read uncommitted的時候binlog必須設置爲row格式。
這個是java設置的一個侷限性,java默認的事務級別是read committed,而mysql默認設置的binlog_format=statement。
將binlog_format設置爲mixed
set global binlog_format=mixed;
過段時間,異常仍在!
設置成row
set global binlog_format=row;
問題解決!
或:
mysql> SET SESSION binlog_format = 'ROW';
mysql> SET GLOBAL binlog_format = 'ROW';
注意: 若手動修改linux下面/etc/my.cnf : binlog_format = row , 需要重啓mysql。