When running in 当以MIXED
logging format, the server automatically switches from statement-based to row-based logging under the following conditions:MIXED
日志记录格式运行时,服务器会在以下条件下自动从基于语句的日志记录切换到基于行的日志记录:
When a function contains 当函数包含UUID()
.UUID()
时。
When one or more tables with 当更新一个或多个具有AUTO_INCREMENT
columns are updated and a trigger or stored function is invoked.AUTO_INCREMENT
列的表并调用触发器或存储函数时。Like all other unsafe statements, this generates a warning if 与所有其他不安全语句一样,如果binlog_format = STATEMENT
.binlog_format = STATEMENT
,则会生成警告。
For more information, see Section 17.5.1.1, “Replication and AUTO_INCREMENT”.有关更多信息,请参阅第17.5.1.1节,“复制和AUTO_INCREMENT”。
When the body of a view requires row-based replication, the statement creating the view also uses it.当视图的主体需要基于行的复制时,创建视图的语句也会使用它。For example, this occurs when the statement creating a view uses the 例如,当创建视图的语句使用UUID()
function.UUID()
函数时,就会发生这种情况。
When a call to a loadable function is involved.当涉及到对可加载函数的调用时。
When 当使用FOUND_ROWS()
or ROW_COUNT()
is used. (Bug #12092, Bug #30244)FOUND_ROWS()
或ROW_COUNT()
时。(错误编号12092,错误编号30244)
When 当使用USER()
, CURRENT_USER()
, or CURRENT_USER
is used. (Bug #28086)USER()
、CURRENT_USER()
或CURRENT_USER
时。(Bug#2086)
When one of the tables involved is a log table in the 当其中一个表是mysql
database.mysql
数据库中的日志表时。
When the 当使用LOAD_FILE()
function is used. (Bug #39701)LOAD_FILE()
函数时。(错误号39701)
When a statement refers to one or more system variables. (Bug #31168)当一个语句引用一个或多个系统变量时。(Bug#31168)
Exception. The following system variables, when used with session scope (only), do not cause the logging format to switch:以下系统变量在与会话作用域(仅)一起使用时,不会导致日志记录格式切换:
For information about determining system variable scope, see Section 5.1.9, “Using System Variables”.有关确定系统变量范围的信息,请参阅第5.1.9节,“使用系统变量”。
For information about how replication treats 有关复制如何处理sql_mode
, see Section 17.5.1.39, “Replication and Variables”.sql_mode
的信息,请参阅第17.5.1.39节,“复制和变量”。
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开始,临时表上的操作不以混合二进制日志记录格式记录,会话中临时表的存在对每条语句使用的日志记录模式没有影响。
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:单个引擎的日志记录功能可以定义如下:
If an engine supports row-based logging, the engine is said to be row-logging capable.如果引擎支持基于行的日志记录,则称该引擎具有行日志记录功能。
If an engine supports statement-based logging, the engine is said to be statement-logging capable.如果引擎支持基于语句的日志记录,则称该引擎具有语句日志记录功能。
A given storage engine can support either or both logging formats. The following table lists the formats supported by each engine.给定的存储引擎可以支持其中一种或两种日志记录格式。下表列出了每个引擎支持的格式。
Storage Engine | Row Logging Supported | |
---|---|---|
ARCHIVE | Yes | Yes |
BLACKHOLE | Yes | Yes |
CSV | Yes | Yes |
EXAMPLE | Yes | No |
FEDERATED | Yes | Yes |
HEAP | Yes | Yes |
InnoDB | Yes | Yes when the transaction isolation level is REPEATABLE READ or SERIALIZABLE ; No otherwise. |
MyISAM | Yes | Yes |
MERGE | Yes | Yes |
NDB | Yes | No |
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).STATEMENT
、ROW
或MIXED
)和存储引擎的日志记录功能(支持语句、支持行、两者都不支持)来确定的。 (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”.
Type | binlog_format | SLC | RLC | Error / Warning | Logged as |
---|---|---|---|---|---|
* | * | No | No | Error: Cannot execute statement | - |
Safe | STATEMENT | Yes | No | - | STATEMENT |
Safe | MIXED | Yes | No | - | STATEMENT |
Safe | ROW | Yes | No | Error: 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. | - |
Unsafe | STATEMENT | Yes | No | Warning: Unsafe statement binlogged in statement format, since BINLOG_FORMAT =
STATEMENT | STATEMENT |
Unsafe | MIXED | Yes | No | Error: 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 . | - |
Unsafe | ROW | Yes | No | Error: Cannot execute statementBINLOG_FORMAT = ROW and at least one table uses a storage engine that is not capable of row-based logging.BINLOG_FORMAT=ROW ,并且至少有一个表使用的存储引擎不能进行基于行的日志记录。 | - |
Row Injection | STATEMENT | Yes | No | Error: Cannot execute row injection | - |
Row Injection | MIXED | Yes | No | Error: Cannot execute row injection | - |
Row Injection | ROW | Yes | No | Error: Cannot execute row injection | - |
Safe | STATEMENT | No | Yes | Error: Cannot execute statementBINLOG_FORMAT = STATEMENT and at least one table uses a storage engine that is not capable of statement-based logging.BINLOG_FORMAT = STATEMENT ,并且至少有一个表使用的存储引擎不能进行基于语句的日志记录。 | - |
Safe | MIXED | No | Yes | - | ROW |
Safe | ROW | No | Yes | - | ROW |
Unsafe | STATEMENT | No | Yes | Error: 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. | - |
Unsafe | MIXED | No | Yes | - | ROW |
Unsafe | ROW | No | Yes | - | ROW |
Row Injection | STATEMENT | No | Yes | Error: Cannot execute row injection: Binary logging is not possible since BINLOG_FORMAT = STATEMENT . | - |
Row Injection | MIXED | No | Yes | - | ROW |
Row Injection | ROW | No | Yes | - | ROW |
Safe | STATEMENT | Yes | Yes | - | STATEMENT |
Safe | MIXED | Yes | Yes | - | STATEMENT |
Safe | ROW | Yes | Yes | - | ROW |
Unsafe | STATEMENT | Yes | Yes | Warning: Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT . | STATEMENT |
Unsafe | MIXED | Yes | Yes | - | ROW |
Unsafe | ROW | Yes | Yes | - | ROW |
Row Injection | STATEMENT | Yes | Yes | Error: Cannot execute row injection: Binary logging is not possible because BINLOG_FORMAT = STATEMENT . | - |
Row Injection | MIXED | Yes | Yes | - | ROW |
Row Injection | ROW | Yes | Yes | - | ROW |
When a warning is produced by the determination, a standard MySQL warning is produced (and is available using 当确定产生警告时,将产生标准MySQL警告(并且可以使用SHOW WARNINGS
). 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
设置为显示警告,则复制副本会将消息打印到错误日志中,以提供有关其状态的信息,例如二进制日志和中继日志坐标,它在哪里开始作业,何时切换到另一个中继日志,何时在断开连接后重新连接,对基于语句的日志记录不安全的语句,等等。