13.4.1.3 SET sql_log_bin Statement语句

SET sql_log_bin = {OFF|ON}

The sql_log_bin variable controls whether logging to the binary log is enabled for the current session (assuming that the binary log itself is enabled). sql_log_bin变量控制是否为当前会话启用二进制日志记录(假设二进制日志本身已启用)。The default value is ON. 默认值为ONTo disable or enable binary logging for the current session, set the session sql_log_bin variable to OFF or ON.要禁用或启用当前会话的二进制日志记录,请将会话sql_log_bin变量设置为OFFON

Set this variable to OFF for a session to temporarily disable binary logging while making changes to the source that you do not want replicated to the replica.为会话将此变量设置为OFF,以便在对不希望复制到复制副本的源进行更改时临时禁用二进制日志记录。

Setting the session value of this system variable is a restricted operation. 设置此系统变量的会话值是一项受限操作。The session user must have privileges sufficient to set restricted session variables. 会话用户必须具有足够的权限来设置受限会话变量。See Section 5.1.9.1, “System Variable Privileges”.请参阅第5.1.9.1节,“系统变量权限”

It is not possible to set the session value of sql_log_bin within a transaction or subquery.无法在事务或子查询中设置sql_log_bin的会话值。

Setting this variable to OFF prevents new GTIDs from being assigned to transactions in the binary log. 将此变量设置为OFF可防止将新的GTID分配给二进制日志中的事务。If you are using GTIDs for replication, this means that even when binary logging is later enabled again, the GTIDs written into the log from this point do not account for any transactions that occurred in the meantime, so in effect those transactions are lost.如果您使用GTID进行复制,这意味着即使以后再次启用二进制日志记录,从这一点写入日志的GTID也不会考虑在此期间发生的任何事务,因此实际上这些事务都会丢失。

mysqldump adds a SET @@SESSION.sql_log_bin=0 statement to a dump file from a server where GTIDs are in use, which disables binary logging while the dump file is being reloaded. mysqldumpSET @@SESSION.sql_log_bin=0语句添加到使用GTID的服务器的转储文件中,这将在重新加载转储文件时禁用二进制日志记录。The statement prevents new GTIDs from being generated and assigned to the transactions in the dump file as they are executed, so that the original GTIDs for the transactions are used.该语句防止在执行转储文件中的事务时生成新的GTID并将其分配给这些事务,以便使用事务的原始GTID。