在使用事务进行Mysql操作时,会抛出异常信息:
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.
java.sql.SQLException: 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.
异常信息提示的比较明确,是事务隔离界别与Mysql的binlog类型不符合。
- 查询Mysql版本,
SELECT VERSION()
结果为5.5.35 - 查询binlog类型,
select @@binlog_format
结果为STATEMENT - 查看数据库连接池参数配置中,
defaultTransactionIsolation=READ_COMMITTED
由此得出,当事务隔离界别为read-commited时,不支持STATEMENT的binlog类型
解决方案
1.修改Mysql服务器的binlog类型为ROW或者MIXED
2.修改连接池参数中事务隔离级别为REPEATABLE-READ
关于binlog类型以及事务隔离级别请参考之前的文章