mysql中做了个定时执行的事件,发现原来起作用,现在不行了。

调用/var/lib/mysql中的错误日志文件,发现一句:

Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave.

原来目前用的mysql版本低,UUID函数不支持MySQL 复制的STATEMENT模式。

先改代码吧,保证对低版本的兼容性:

BEGIN
-- UUID函数属于不确定性函数,为此不支持MySQL 复制的STATEMENT模式,但是支持MIXED、ROW二种模式
-- 在复制模式下,需要用到UUID()函数,则一定要使用基于行/混合模式复制方式。
set binlog_format = MIXED;
insert into Users(userName,guid,userpinyin,userpy,uper)
select DISTINCT userName, UUID(), to_pinyin(userName),to_pinyinsx(userName),Domain from t_zhangdan a
where not exists(select 1 from Users where userName=a.userName);
END