为什么mysql事件计划不能在数据库localhost中运行? [英] Why mysql event schedule not working in database localhost?

查看:96
本文介绍了为什么mysql事件计划不能在数据库localhost中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经运行: SET GLOBAL event_scheduler = ON;



我的事件调度程序脚本是这样的: / p>

  CREATE EVENT update_status 
ON SCHEDULE EVERY 2 MINUTE
DO
更新customer_group
SET is_status = 1
WHERE CURRENT_TIMESTAMP> = end_date

数据库localhost中没有更新值



即使在数据库服务器中,它是一个更新



解决我的问题的任何解决方案? >

谢谢

解决方案

查看以下内容



发行选择CURRENT_TIMESTAMP;

  select count(*)asCount 
from customer_group
where is_status = 1 and CURRENT_TIMESTAMP> = end_date;

换句话说,做一些侦察。事件成功或失败,因为他们没有用户界面。



运行一些命令,如:

  show variables where variable_name ='event_scheduler'; 

- 目前关闭(或可能是开启)



在创建时指定事件的开始时间,并指定 ON COMPLETION PRESERVE ,例如

  drop event if exists`Every_5_Minutes_QuestionUpdateImport`; 
DELIMITER $$
创建活动Every_5_Minutes_QuestionUpdateImport
每次5分钟起始时间2015-09-01 00:00:00'
完成保存
DO BEGIN
-
- 您的所有陈述都在这里
-
END $$
DELIMITER;

打开事件处理程序:

  SET GLOBAL event_scheduler = ON; - 转过身,确认以下

确认:

  show variables where variable_name ='event_scheduler'; 

通过数据库名称检查特定数据库中的所有事件的状态:

 从stackoverflow显示事件; -  note stackoverflow是我的数据库名称



在当前选定的数据库中按名称禁用或启用某个事件:

  ALTER EVENT Every_2_Minutes_QuestionUpdateImport disable; 
ALTER EVENT Every_2_Minutes_QuestionUpdateImport enable;

最后但并非最不重要的是,当我写一个新的事件时,我总是在事件中添加要记录到日志表(使用insert语句和日期时间为 now())的语句。这样,我知道它被解雇了,像你这样的where子句中的数据也许并没有给我一个错误的阅读在整个事情。



我的意思是我疯了到处都是。最初,我稍后再说一遍:

  set filename:= concat('c:\\datavault\\\ \\stackoverflow \\app \\\\\\processMe _',LPAD(@idToPerform,8,'0'),'。txt'); 
set logMsg:= concat(看来我是处理这个东西:,filename);

插入EvtsLog(incarnationId,evtN​​ame,step,debugMsg,dtWhenLogged)
选择incarnationId,evtAlias,10,logMsg,now(); - 10:中间的某个地方

记住所有的实际目的(除了你的桌子你真正关心你的问题)...我的这个 EvtsLog 是你唯一的用户界面,作为一个活动程序员和你最好的朋友。



查看手册页面,了解 ON完成保存意味着以及其他的东西。


I had run : SET GLOBAL event_scheduler = ON;

My event scheduler script is like this :

CREATE EVENT update_status
ON SCHEDULE EVERY 2 MINUTE
DO
UPDATE customer_group
SET is_status = 1
WHERE CURRENT_TIMESTAMP >= end_date

It's not updating value in database localhost

Even though, in database server, it's an update

Any solution to solve my problem?

Thank you

解决方案

Look into the following.

Issue a select CURRENT_TIMESTAMP; or

select count(*) as theCount
from customer_group
where is_status=1 and CURRENT_TIMESTAMP >= end_date;

In other words, do some recon. Events succeed or fail silently as they have no user interface.

Run some commands like:

show variables where variable_name='event_scheduler';

-- currently OFF (or it could be ON)

Specify the start time for your event during creation, and specify ON COMPLETION PRESERVE such as

drop event if exists `Every_5_Minutes_QuestionUpdateImport`;
DELIMITER $$
CREATE EVENT `Every_5_Minutes_QuestionUpdateImport`
  ON SCHEDULE EVERY 5 MINUTE STARTS '2015-09-01 00:00:00'
  ON COMPLETION PRESERVE
DO BEGIN
    --
    -- all your statements go here
    -- 
END$$
DELIMITER ;

Turn on the event handler:

SET GLOBAL event_scheduler = ON;  -- turn her on and confirm below

Confirm it:

show variables where variable_name='event_scheduler';

Examine the status of all events in a particular database by database name:

show events from stackoverflow; -- note stackoverflow is my database name 

Disable or enable a certain event by name in the current selected db:

ALTER EVENT Every_2_Minutes_QuestionUpdateImport disable;
ALTER EVENT Every_2_Minutes_QuestionUpdateImport enable;

And last but not least, when I am writing a new Event, I always add initially in the event statements to log to a log table (with an insert statement and a datetime of now()). That way, I know it fired and that data in a where clause like yours perhaps is not giving me a wrong read on the whole thing.

And I mean I go crazy all over the place. Initially, then I rem it out later:

    set filename:=concat('c:\\datavault\\stackoverflow\\app01\\batches\\processMe_',LPAD(@idToPerform, 8, '0'),'.txt');
    set logMsg:=concat("It would appear I am to process this thing: ",filename);

    insert EvtsLog(incarnationId,evtName,step,debugMsg,dtWhenLogged)
    select incarnationId,evtAlias,10,logMsg,now(); -- 10: some step somewhere in the middle

Remember for all practical purposes (except maybe your table you really care about from your question) ... that EvtsLog of mine is your only user interface as an Events programmer and your best friend.

Look at the manual page for what ON COMPLETION PRESERVE means as well as other things.

这篇关于为什么mysql事件计划不能在数据库localhost中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆