这个例子有效:
MariaDB [test]> SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [test]> INSERT INTO test(id, value) VALUES (1, 'test'), (2, 'test 2');
Query OK, 2 rows affected (0.37 sec)
Records: 2 Duplicates: 0 Warnings: 0
MariaDB [test]> SELECT * FROM test;
+------+--------+
| id | value |
+------+--------+
| 1 | test |
| 2 | test 2 |
+------+--------+
2 rows in set (0.00 sec)
MariaDB [test]> COMMIT;
但当我改变交易级别时:
MariaDB [test]> SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
Query OK, 0 rows affected (0.00 sec)
MariaDB [test]> INSERT INTO test(id, value) VALUES (1, 'test'), (2, 'test 2');
ERROR 1665 (HY000): Cannot execute statement: impossible to write to binary log
since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine lim
ited to row-based logging. InnoDB is limited to row-logging when transaction iso
lation level is READ COMMITTED or READ UNCOMMITTED.
MariaDB [test]> SELECT * FROM test;
Empty set (0.00 sec)
MariaDB [test]> COMMIT;
Query OK, 0 rows affected (0.00 sec)
如何解决这个问题?
答案 0 :(得分:1)
在这种情况下,错误消息非常详细。根据{{3}}上的mysql文档:
如果您使用InnoDB表并且事务隔离级别为READ COMMITTED或READ UNCOMMITTED,则只能使用基于行的日志记录。可以将日志记录格式更改为STATEMENT,但在运行时这样做会导致错误,因为InnoDB无法再执行插入操作。
因此,您必须将binlog_format设置为ROW
:
SET SESSION binlog_format = 'ROW';