5.4.4.3 Mixed Binary Logging Format混合二进制日志记录格式

When running in MIXED logging format, the server automatically switches from statement-based to row-based logging under the following conditions:当以MIXED日志记录格式运行时,服务器会在以下条件下自动从基于语句的日志记录切换到基于行的日志记录:

In earlier releases, when mixed binary logging format was in use, if a statement was logged by row and the session that executed the statement had any temporary tables, all subsequent statements were treated as unsafe and logged in row-based format until all temporary tables in use by that session were dropped.在早期版本中,当使用混合二进制日志记录格式时,如果一条语句是按行记录的,并且执行该语句的会话有任何临时表,则所有后续语句都将被视为不安全的,并以基于行的格式记录,直到该会话使用的所有临时表都被删除为止。As of MySQL 8.0, operations on temporary tables are not logged in mixed binary logging format, and the presence of temporary tables in the session has no impact on the logging mode used for each statement.从MySQL 8.0开始,临时表上的操作不以混合二进制日志记录格式记录,会话中临时表的存在对每条语句使用的日志记录模式没有影响。

Note注意

A warning is generated if you try to execute a statement using statement-based logging that should be written using row-based logging.如果尝试使用基于语句的日志记录执行语句,则会生成警告,而该语句应该使用基于行的日志记录编写。The warning is shown both in the client (in the output of SHOW WARNINGS) and through the mysqld error log. 该警告显示在客户端(SHOW WARNINGS的输出中)和mysqld错误日志中。A warning is added to the SHOW WARNINGS table each time such a statement is executed. 每次执行此类语句时,都会向SHOW WARNINGS表中添加一个警告。However, only the first statement that generated the warning for each client session is written to the error log to prevent flooding the log.但是,只有为每个客户端会话生成警告的第一条语句会写入错误日志,以防止淹没日志。

In addition to the decisions above, individual engines can also determine the logging format used when information in a table is updated. 除了上述决策之外,各个引擎还可以确定更新表中信息时使用的日志记录格式。The logging capabilities of an individual engine can be defined as follows:单个引擎的日志记录功能可以定义如下:

A given storage engine can support either or both logging formats. The following table lists the formats supported by each engine.给定的存储引擎可以支持其中一种或两种日志记录格式。下表列出了每个引擎支持的格式。

Storage EngineRow Logging SupportedStatement Logging Supported支持语句日志记录
ARCHIVEYesYes
BLACKHOLEYesYes
CSVYesYes
EXAMPLEYesNo
FEDERATEDYesYes
HEAPYesYes
InnoDBYesYes when the transaction isolation level is REPEATABLE READ or SERIALIZABLE; No otherwise.
MyISAMYesYes
MERGEYesYes
NDBYesNo

Whether a statement is to be logged and the logging mode to be used is determined according to the type of statement (safe, unsafe, or binary injected), the binary logging format (STATEMENT, ROW, or MIXED), and the logging capabilities of the storage engine (statement capable, row capable, both, or neither).是否记录语句和使用的日志记录模式是根据语句类型(安全、不安全或二进制注入)、二进制日志记录格式(STATEMENTROWMIXED)和存储引擎的日志记录功能(支持语句、支持行、两者都不支持)来确定的。 (Binary injection refers to logging a change that must be logged using ROW format.)(二进制注入是指记录必须使用ROW格式记录的更改。)

Statements may be logged with or without a warning; failed statements are not logged, but generate errors in the log. 可以记录有警告或没有警告的声明;失败的语句不会被记录,但会在日志中生成错误。This is shown in the following decision table. 如下决策表所示。Type, binlog_format, SLC, and RLC columns outline the conditions, and Error / Warning and Logged as columns represent the corresponding actions. SLC stands for statement-logging capable, and RLC stands for row-logging capable.

Typebinlog_formatSLCRLCError / WarningLogged as
**NoNoError: Cannot execute statement: Binary logging is impossible since at least one engine is involved that is both row-incapable and statement-incapable.:二进制日志记录是不可能的,因为至少有一个引擎同时不支持行和语句。-
SafeSTATEMENTYesNo-STATEMENT
SafeMIXEDYesNo-STATEMENT
SafeROWYesNoError: Cannot execute statement: Binary logging is impossible since BINLOG_FORMAT = ROW and at least one table uses a storage engine that is not capable of row-based logging.-
UnsafeSTATEMENTYesNoWarning: Unsafe statement binlogged in statement format, since BINLOG_FORMAT = STATEMENTSTATEMENT
UnsafeMIXEDYesNoError: Cannot execute statement: Binary logging of an unsafe statement is impossible when the storage engine is limited to statement-based logging, even if BINLOG_FORMAT = MIXED.-
UnsafeROWYesNoError: Cannot execute statement: Binary logging is impossible since BINLOG_FORMAT = ROW and at least one table uses a storage engine that is not capable of row-based logging.:二进制日志记录是不可能的,因为BINLOG_FORMAT=ROW,并且至少有一个表使用的存储引擎不能进行基于行的日志记录。-
Row InjectionSTATEMENTYesNoError: Cannot execute row injection: Binary logging is not possible since at least one table uses a storage engine that is not capable of row-based logging.:二进制日志记录是不可能的,因为至少有一个表使用的存储引擎不能进行基于行的日志记录。-
Row InjectionMIXEDYesNoError: Cannot execute row injection: Binary logging is not possible since at least one table uses a storage engine that is not capable of row-based logging.:二进制日志记录是不可能的,因为至少有一个表使用的存储引擎不能进行基于行的日志记录。-
Row InjectionROWYesNoError: Cannot execute row injection: Binary logging is not possible since at least one table uses a storage engine that is not capable of row-based logging.:二进制日志记录是不可能的,因为至少有一个表使用的存储引擎不能进行基于行的日志记录。-
SafeSTATEMENTNoYesError: Cannot execute statement: Binary logging is impossible since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine that is not capable of statement-based logging.:二进制日志记录是不可能的,因为BINLOG_FORMAT = STATEMENT,并且至少有一个表使用的存储引擎不能进行基于语句的日志记录。-
SafeMIXEDNoYes-ROW
SafeROWNoYes-ROW
UnsafeSTATEMENTNoYesError: Cannot execute statement: Binary logging is impossible since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine that is not capable of statement-based logging.-
UnsafeMIXEDNoYes-ROW
UnsafeROWNoYes-ROW
Row InjectionSTATEMENTNoYesError: Cannot execute row injection: Binary logging is not possible since BINLOG_FORMAT = STATEMENT.-
Row InjectionMIXEDNoYes-ROW
Row InjectionROWNoYes-ROW
SafeSTATEMENTYesYes-STATEMENT
SafeMIXEDYesYes-STATEMENT
SafeROWYesYes-ROW
UnsafeSTATEMENTYesYesWarning: Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT.STATEMENT
UnsafeMIXEDYesYes-ROW
UnsafeROWYesYes-ROW
Row InjectionSTATEMENTYesYesError: Cannot execute row injection: Binary logging is not possible because BINLOG_FORMAT = STATEMENT.-
Row InjectionMIXEDYesYes-ROW
Row InjectionROWYesYes-ROW

When a warning is produced by the determination, a standard MySQL warning is produced (and is available using SHOW WARNINGS). 当确定产生警告时,将产生标准MySQL警告(并且可以使用SHOW WARNINGS)。The information is also written to the mysqld error log. 该信息也会写入到mysqld错误日志中。Only one error for each error instance per client connection is logged to prevent flooding the log. The log message includes the SQL statement that was attempted.每个客户端连接的每个错误实例只记录一个错误,以防止日志泛滥。日志消息包括尝试的SQL语句。

If a replica has log_error_verbosity set to display warnings, the replica prints messages to the error log to provide information about its status, such as the binary log and relay log coordinates where it starts its job, when it is switching to another relay log, when it reconnects after a disconnect, statements that are unsafe for statement-based logging, and so forth.如果复制副本将log_error_verbosity设置为显示警告,则复制副本会将消息打印到错误日志中,以提供有关其状态的信息,例如二进制日志和中继日志坐标,它在哪里开始作业,何时切换到另一个中继日志,何时在断开连接后重新连接,对基于语句的日志记录不安全的语句,等等。