The server uses several logging formats to record information in the binary log:服务器使用几种日志记录格式在二进制日志中记录信息:
Replication capabilities in MySQL originally were based on propagation of SQL statements from source to replica. MySQL中的复制功能最初是基于SQL语句从源到副本的传播。This is called statement-based logging. 这称为基于语句的日志记录。You can cause this format to be used by starting the server with 您可以通过使用--binlog-format=STATEMENT
.--binlog-format=STATEMENT
启动服务器来使用此格式。
In row-based logging (the default), the source writes events to the binary log that indicate how individual table rows are affected. 在基于行的日志记录(默认情况下)中,源将事件写入二进制日志,指示各个表行受到的影响。You can cause the server to use row-based logging by starting it with 您可以通过使用--binlog-format=ROW
.--binlog-format=ROW
启动服务器,使其使用基于行的日志记录。
A third option is also available: mixed logging. With mixed logging, statement-based logging is used by default, but the logging mode switches automatically to row-based in certain cases as described below. 第三个选项也可用:混合日志记录。对于混合日志记录,默认情况下使用基于语句的日志记录,但在某些情况下,日志记录模式会自动切换到基于行的日志记录模式,如下所述。You can cause MySQL to use mixed logging explicitly by starting mysqld with the option 通过使用选项--binlog-format=MIXED
.--binlog-format=MIXED
启动mysqld,可以使MySQL显式地使用混合日志记录。
The logging format can also be set or limited by the storage engine being used. This helps to eliminate issues when replicating certain statements between a source and replica which are using different storage engines.日志记录格式也可以由所使用的存储引擎设置或限制。这有助于消除在使用不同存储引擎的源和复制副本之间复制某些语句时出现的问题。
With statement-based replication, there may be issues with replicating nondeterministic statements. In deciding whether or not a given statement is safe for statement-based replication, MySQL determines whether it can guarantee that the statement can be replicated using statement-based logging. 对于基于语句的复制,复制不确定性语句可能会出现问题。在决定给定的语句对于基于语句的复制是否安全时,MySQL确定是否可以保证使用基于语句的日志记录来复制该语句。If MySQL cannot make this guarantee, it marks the statement as potentially unreliable and issues the warning, Statement may not be safe to log in statement format.如果MySQL不能保证这一点,它会将语句标记为潜在的不可靠,并发出警告,语句可能不安全登录到语句格式中。
You can avoid these issues by using MySQL's row-based replication instead.您可以使用MySQL的基于行的复制来避免这些问题。