简体   繁体   English

mysql-在存储过程中创建事件

[英]mysql - create event in store procedure

How to create event inside store procedure? 如何在存储过程中创建事件?

This is what I been trying to do, and it tells me that I have a syntax error, only it doesn't tells me where. 这是我一直在尝试的操作,它告诉我语法错误,只是没有告诉我在哪里。

-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `update_leaderboard`()
BEGIN


CREATE EVENT update_leaderboard_event
    ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 minute
    DO call update_leaderboard();



END

Edit: According to my MySql(last line) it should be possible: 编辑:根据我的MySql(最后一行),应该是可能的:

Syntax”. 句法”。 You can create an event as part of a stored routine, but an event cannot be created by another event. 您可以将事件创建为存储例程的一部分,但是另一个事件不能创建一个事件。

Edit2 found the problem: Edit2发现了问题:

Error 1576: Recursion of EVENT DDL statements is forbidden when body is present 错误1576:存在正文时,禁止递归EVENT DDL语句

But no solution yet, how do I do it then? 但是还没有解决方案,那我该怎么办?

You cant create inside procedure. 您无法创建内部过程。 You need to define it separately. 您需要单独定义它。

Just check Mysql Event Scheduler 只需检查Mysql Event Scheduler
detail blog: http://goo.gl/6Hzjvg 详细博客: http//goo.gl/6Hzjvg

"CREATE EVENT" and "ALTER EVENT" we created at special external application by direct "Request" to MySQL-engine DataBase. 我们在特殊的外部应用程序中通过直接向MySQL引擎数据库请求“请求”而创建了“创建事件”和“更改事件”。

Insert rows from the triggers or procedures to the special table "Need create_alter event" and special external application cyclically reading rows, then directly send requests about create/alter events to MySQL-engine DataBase 将触发器或过程中的行插入到特殊表“ Need create_alter event”,特殊外部应用程序循环读取行,然后将有关create / alter事件的请求直接发送到MySQL引擎数据库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM