Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.

一.问题描述 

014-12-15 20:00:29 4398 [Warning] Unsafe statement written to the binary log using statement format since

BINLOG_FORMAT = STATEMENT. INSERT... ON DUPLICATE KEY UPDATE  on a table with more than

one UNIQUE KEY is unsafe Statement: INSERT INTO `longxibendi` (`lxid`, `l_id`, `l_aplply`, `l_types`, `ctimes`) VALUES

(75692, 218, 8, 2, 1418644829) ON DUPLICATE KEY

UPDATE `ctimes`=1418644829

一个mysql master 的err log 报上面的错误。

二.问题原因

查了下原因,longxibendi这个表上有2个唯一键。则使用 INSERT... ON DUPLICATE KEY UPDATE   ,且当前数据库binlog_format是statement格式,这种sql语句就会报unsafe。

查了下手册

  • INSERT ... ON DUPLICATE KEY UPDATE statements on tables with multiple primary or unique keys.  When executed
    against a table that contains more than one primary or unique key, this statement is considered unsafe, being sensitive to the order in which the storage engine checks the keys, which is not deterministic, and on which the choice of rows updated by the MySQL
    Server depends.

    An INSERT
    ... ON DUPLICATE KEY UPDATE
     statement against a table having more than one unique or primary key is marked as unsafe for statement-based replication beginning with MySQL 5.6.6. (Bug #11765650, Bug #58637)

http://dev.mysql.com/doc/refman/5.6/en/replication-rbr-safe-unsafe.html

看官方解释,是 server层把数据传给innodb引擎,innodb引擎检查key值比较敏感造成的。

个人理解,可能与server与innodb每次只传1行数据有关。

三.问题解决

两种办法:

1.修改binlog_format格式为mixed;

登陆mysql,执行 set global binlog_format=MIXED;

2.不要使用这类sql;

其中,第1种方法,需要注意下。

如果是 master->slave  结构的数据库架构。并且 slave上开启了 log_slave_updates。那么在master上修改完binlog格式,开启了log_slave_updates的从库,会同布中断。

所以,需要先在 slave上,设置 binlog_format=mixed,之后再在master上设置。slave报错信息如下:

Last_SQL_Errno: 1666

Last_SQL_Error: Error executing row event: ‘Cannot execute statement: impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT.‘

时间: 2024-11-06 09:17:28

Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.的相关文章

MySQL:Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT...

1:错误日志大量错误 150602 14:40:02 [Warning] Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT... SELECT... ON DUPLICATE KEY UPDATE is unsafe because the order in which rows are retrieved by the SELECT

JAVA调用mysql数据操作时出现错误:impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT.'

使用mysql做持久化报错:Cannot execute statement: impossible to write to binary log since BINLOG_FORM ActiveMQ中如果使用mysql innodb的同时,开启了binlog,那么在ack消息的时候,日志里就可会报错:java.sql.SQLException: Cannot execute statement: binlogging impossible since BINLOG_FORMAT = STATE

MySQL 二进制日志(Binary Log)

同大多数关系型数据库一样,日志文件是MySQL数据库的重要组成部分.MySQL有几种不同的日志文件,通常包括错误日志文件,二进制日志,通用日志,慢查询日志,等等.这些日志可以帮助我们定位mysqld内部发生的事件,数据库性能故障,记录数据的变更历史,用户恢复数据库等等.二进制日志,也叫binary log,是MySQL Server中最为重要的日志之一,本文主要描述二进制日志. 1.MySQL日志文件系统的组成   a.错误日志:记录启动.运行或停止mysqld时出现的问题.   b.通用日志:

impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage isolation level is READ COMMITTED or READ UNCOMMITTED

执行jdbc查询时抛出异常: Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging. InnoDB is limited to row-logging when transaction isolation level is

ActiveMQ中使用mysql做持久化报错:Cannot execute statement: impossible to write to binary log since BINLOG_FORM

ActiveMQ中如果使用mysql innodb的同时,开启了binlog,那么在ack消息的时候,日志里就可会报错:java.sql.SQLException: Cannot execute statement: binlogging impossible since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-logging. InnoDB is limited

关于binary log那些事

阅读目录(Content) 1 what's binary log 2 Binary Logging Options and Variables 2.1 基础参数 2.2 重要参数(sync_binlog=0丢失数据的描述有疑问,目前查阅相关资料跟咨询业界人士中....) 3 Binary Logging Formats 3.1 binlog_format=statement 3.2 binlog_format=row 3.2.1 binlog_row_image默认full,binlog_ro

关于binary log一点总结[转]

阅读目录(Content) 1 what's binary log 2 Binary Logging Options and Variables 2.1 基础参数 3 Binary Logging Formats 3.1 binlog_format=statement 3.2 binlog_format=row 3.2.1 binlog_row_image默认full,binlog_rows_query_log_events默认false 3.2.2 binlog_rows_query_log_

MySQL二进制日志(binary log)总结

本文出处:http://www.cnblogs.com/wy123/p/7182356.html (保留出处并非什么原创作品权利,本人拙作还远远达不到,仅仅是为了链接到原文,因为后续对可能存在的一些错误进行修正或补充,无他) 今天无意中发现了一个云栖社区举行的MySQL“第一季:挑战玄惭之 慢SQL性能优化赛”,在测试服务器上执行其测试脚本写入数据的时候报错提示如下,Multi-statement transaction required more than 'max_binlog_cache_

binary log初探

binary log是mysql中一个重要的部分,主要作用有两个: Replication:在master端开启binary log后,log会记录所有数据库的改动,然后slave端获取这个Log文件内容就可以在slave端进行同样的操作. 备份:在某个时间点a做了一次备份,然后利用binary log记录从这个时间点a后的所有数据库的改动,然后下一次还原的时候,利用时间点a的备份文件和这个binary log文件,就可以将数据还原. 与binary log相关的参数如下: log-bin和lo