Mir Abzal Ali
Mir Abzal Ali

Reputation: 579

mysql: unrecognized statement type. (near SCHEDULE) when try to create event schedule

I'm trying to create event schedule but phpmyadmin shows error on left 'unrecognized statement type. (near SCHEDULE)'. MySql version is 10.1.8. I really don't understand whats wrong with this code or MySql/phpmyadmin or any others configuration.

    DELIMITER $$
    CREATE 
        EVENT `archive_blogs` 
        ON SCHEDULE
        EVERY 1 DAY
        STARTS '20:00:00' ON COMPLETION PRESERVE ENABLE 
        DO BEGIN
            .....
        END */$$
    DELIMITER ;

snap error: unrecognized statement type. (near SCHEDULE)

enter image description here

Upvotes: 2

Views: 11147

Answers (2)

Drew
Drew

Reputation: 24960

try this, it seems to want a date too.

DELIMITER $$
CREATE EVENT `archive_blogs` 
    ON SCHEDULE
    EVERY 1 DAY
    STARTS '2015-11-23 20:00:00' 
    ON COMPLETION PRESERVE ENABLE 
    DO 
        select 8 as 'eight';
    $$
DELIMITER ;

It gets thru on my system.

Create Event manual page.

Upvotes: 1

malyy
malyy

Reputation: 874

MySql version is 10.1.8

Are you sure that it is MySQL? May be MariaDB? Where do you get this error - script, phpMyAdmin? Did you try to execute it from consle?

as for the

STARTS '20:00:00'

try the following insted

STARTS CONCAT(DATE(NOW()+INTERVAL 1 DAY ), ' 20:00:00')

from MySQL doc:

To repeat actions at a regular interval, use an EVERY clause. The EVERY keyword is followed by an interval as described in the previous discussion of the AT keyword. (+ INTERVAL is not used with EVERY.) For example, EVERY 6 WEEK means “every six weeks”.

Although + INTERVAL clauses are not permitted in an EVERY clause, you can use the same complex time units permitted in a + INTERVAL.

An EVERY clause may contain an optional STARTS clause. STARTS is followed by a timestamp value that indicates when the action should begin repeating, and may also use + INTERVAL interval to specify an amount of time “from now”. For example, EVERY 3 MONTH STARTS CURRENT_TIMESTAMP + INTERVAL 1 WEEK means “every three months, beginning one week from now”. Similarly, you can express “every two weeks, beginning six hours and fifteen minutes from now” as EVERY 2 WEEK STARTS CURRENT_TIMESTAMP + INTERVAL '6:15' HOUR_MINUTE. Not specifying STARTS is the same as using STARTS CURRENT_TIMESTAMP—that is, the action specified for the event begins repeating immediately upon creation of the event.

An EVERY clause may contain an optional ENDS clause. The ENDS keyword is followed by a timestamp value that tells MySQL when the event should stop repeating. You may also use + INTERVAL interval with ENDS; for instance, EVERY 12 HOUR STARTS CURRENT_TIMESTAMP + INTERVAL 30 MINUTE ENDS CURRENT_TIMESTAMP + INTERVAL 4 WEEK is equivalent to “every twelve hours, beginning thirty minutes from now, and ending four weeks from now”. Not using ENDS means that the event continues executing indefinitely.

ENDS supports the same syntax for complex time units as STARTS does.

You may use STARTS, ENDS, both, or neither in an EVERY clause.

Upvotes: 2

Related Questions