建立表記錄event執行過程
createtable
`mysql`.`event_history` (
`dbname` varchar(
128) not null default ''
, `eventname` varchar(
128) not null default ''
, `starttime` datetime
not null default '
0000-01-01 00:00:00',
`endtime` datetime default null,
`issuccess` int(
11) default null,
`duration` int(
11) default null,
`errormessage` varchar(
512) default null,
`randno` int(
11) default null,
primary key (`dbname`,`eventname`,`starttime`),
key `idx_endtime` (`endtime`),
key `idx_starttime_randno` (`starttime`,`randno`)
) engine=innodb default charset=utf8mb4 collate utf8mb4_general_ci;
example
1:
delimiter $$create definer=`root`@`localhost` event
`event1`
#修改以下排程資訊
on schedule every 1 day starts '
2014-01-03 01:00:00'on
completion preserve enable
dobegin
declare r_code
char(5) default '
00000';
declare r_msg
text
; declare v_error
integer
; declare v_starttime datetime default now();
declare v_randno
integer default floor(rand()*100001
);
#修改下面的作業名(該作業的名稱)
insert
into mysql.event_history (dbname,eventname,starttime,randno) values (database(),'
event1
', v_starttime,v_randno);
begin
#異常處理段
declare
continue
handler
forsqlexception
begin
set v_error = 1
;
get diagnostics condition 1 r_code = returned_sqlstate , r_msg =message_text;
end;
#此處為實際呼叫的使用者程式過程
call
test.usp_test1();
end;
update mysql.event_history set endtime=now(),issuccess=isnull(v_error),duration=timestampdiff(second,starttime,now()), errormessage=concat('
error=
',r_code,'
, message=
',r_msg),randno=null where starttime=v_starttime and randno=v_randno;
end$$
delimiter ;
2:
create table tbl_v(id int
notnull auto_increment,
user varchar(
20) collate utf8mb4_general_ci default ''
,createtime datetime default now(),
primary key (id)
)engine=innodb auto_increment default charset=utf8mb4 collate utf8mb4_general_ci;
create event if notexists event_1
on schedule every
5second
on completion perserve
do insert into tbl_v (user) values (
'uiop
');
3:
delimiter //drop procedure if exists procedure_flush_hosts //create procedure procedure_flush_hosts()begin
flush hosts;
end //delimiter ;
drop event isexists event_flush_hosts;
create event event_flush_hosts
on schedule every
120second
on completion preserve disabled
do call procedure_flush_hosts();
開啟event
alter event event_1 on completion preserve enable;
關閉event
alter event event_1 on completion preserve disable;
Mysql Event事件相關
常用語句 建立定時器,並執行sql語句塊 delimiter create event b on schedule every 1 second on completion preserve enable do begin insert into test a values now insert i...
MYSQL EVENT事件無法生效
事件 event 是mysql在相應的時刻呼叫的過程式資料庫物件,它由乙個特定的執行緒來管理的,它有兩種排程方式。一次性呼叫。週期性呼叫。最近在使用週期性呼叫時,發現無法生效 我們歸納為兩種問題 全域性的event狀態預設是關閉的 新建事件的狀態為disable 解決方案 問題1 將全域性event...
MapReduce作業調優
1,map緩衝區記憶體改大 環形緩衝區越大,溢寫次數越少,磁碟 io 的次數越少,執行速度就越快 預設100m,可配置 2,map輸出壓縮 減少io 可配置 3,reduce拉取過來的資料直接存記憶體,避免落盤,這樣合併也能在記憶體中完成 可配置 4,shuffle中的多次磁碟io操作非常消耗效能,...