phpMyAdmin event error #1542 interval too big - mysql

I have an MySQL event that deletes any rows older than 1 month. I now want to change that so it deletes rows older than 6 months (it cleans up a database for messages sent in a game).
My (edited) MySQL event is:
DELETE FROM messages WHERE date < (NOW() - INTERVAL 6 MONTH)
The error I get is:
The following query has failed: "CREATE DEFINER=`admin`#`localhost` EVENT `delete msgs` ON SCHEDULE EVERY 0 DAY_HOUR STARTS '2013-07-19 18:00:00' ON COMPLETION PRESERVE ENABLE DO DELETE FROM messages WHERE date < (NOW() - INTERVAL 6 MONTH)"
MySQL said: #1542 - INTERVAL is either not positive or too big
The event functions fine but I can't even save it as it is now. If I open the event and immediately save I get the same error.

Juergen d basically answered my question in a comment. The interval was set to "EVERY 0 DAY_HOUR" while in phpmyadmin it was set to "EVERY '0_10' DAY_HOUR". I was able to save it before with the '0_10' but apparently that doesn't work anymore, or maybe never worked (even though the event did it's thing).
I changed that to "EVERY 10 HOUR" and now it saves fine.

Related

Why change input interval value on mysql?

I want create event that execute every monday 00:00:00.
I created event but don't work. In my Opinion, reason is interval value.
I use EVERY 1 WEEK option but mysql display 7 interval value. Is it right reason? If yes why don't input correct value?
This is my create query
CREATE EVENT IF NOT EXISTS clear_temp_week_news_count
ON SCHEDULE every 1 week starts CURRENT_DATE + INTERVAL 7 - WEEKDAY(CURRENT_DATE) DAY
on completion preserve enable
DO
delete from temp_week_news_count;
This is result when use "show events;"
enter image description here
I did check db status on with "SHOW VARIABLES LIKE 'event%';"

MySQL Recurring event not executing

I have a recurring event set to execute each 1 minute in MySQL:
BEGIN
DELETE FROM session WHERE `date` < DATE_SUB(NOW(), INTERVAL 1 MINUTE);
END
For some reason, my session entries, such as one with the date parameter of
2019-01-19 18:28:24
are not being deleted, despite the fact that SELECT NOW(); currently returns
2019-01-19 18:44:15
So this is more than a minute after the creation date and proves that timezones aren't the problem. Is my event simply failing to execute or is there a problem with the event itself?
EDIT: Please note that the event is set to execute each minute AND delete session entries that are more than a minute old, not just one or the other. The recurring interval isn't shown above, but I've confirmed that it is 1 minute.
I had to run
SET GLOBAL event_scheduler = on;
in order to fix the issue. I had rebooted my XAMPP local server since the last time I tested this, which is why it suddenly stopped working.

mysql event runs but doesnt execute the query

I used to have an archiving event that used to run once everyday without a problem but then recently when I checked, I found out that my event still runs but the query wasn't executed. So I dropped the old event and recreated it and only changed the name and the execution time but now it says there's something wrong with the syntax when I use a mysql syntax checker but it runs using php the only problem is it executes the 2nd query which is delete instead of the 1st first query which is insert. The event looks like this:
CREATE DEFINER=`ricoj`#`%` EVENT `log_archiving` ON SCHEDULE EVERY 1 DAY STARTS
'2016-06-29 12:00:00' ON COMPLETION PRESERVE ENABLE DO BEGIN
insert into archives
select * from app_log where date_sub(curdate( ) , interval 75 DAY) >= created_datetime;
delete from app_log where date_sub(curdate( ) , interval 75 DAY) >= created_datetime;
END

MySQL EVENT does not execute

I have an event that deletes record on a table that are a month old. But it does not seem to execute.
DELIMITER $
CREATE EVENT delete_wykofile_back
ON SCHEDULE EVERY 1 MINUTE
STARTS CURRENT_TIMESTAMP + INTERVAL 1 DAY
ENDS CURRENT_TIMESTAMP + INTERVAL 5 YEAR
ON COMPLETION PRESERVE
DO
BEGIN
DELETE FROM factory.wyko_file_backup WHERE date_inserted < DATE_SUB(NOW(), INTERVAL 1 MONTH);
END$
DELIMITER ;
What I've done so far:
I have followed and set global event_scheduler to ON based from this question
I've also check this question, but to no avail.
There's also no answer from this question.
The account im using is a superuser based from this.
SHOW EVENTS;
SHOW PROCESSLIST;
I am using MySQL Workbench 6.2. I am running the event with 1 minute interval for testing.
STARTS CURRENT_TIMESTAMP + INTERVAL 1 DAY
needs to be the current date or a past date. Right now its set up to start on 12/4/2015.

How to delete a MySQL record after a certain time

I want to delete some messages from my MySQL database after 7 days.
My message table rows have this format:
id | message | date
The date is a timestamp in the normal format; 2012-12-29 17:14:53
I was thinking that an MySQL event would be the way to go instead of a cron job.
I have what I guess is a simple question to an experienced SQL person, how do I code the delete messages portion in brackets below?
An example would be appreciated, Thanks.
DELIMITER $$
CREATE EVENT delete_event
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 DAY
ON COMPLETION PRESERVE
DO
BEGIN
DELETE messages WHERE date >= (the current date - 7 days);
END;
$$;
You can try using this condition:
WHERE date < DATE_SUB(NOW(), INTERVAL 7 DAY)
So that the whole SQL script looks like this:
CREATE EVENT delete_event
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 DAY
ON COMPLETION PRESERVE
DO BEGIN
DELETE messages WHERE date < DATE_SUB(NOW(), INTERVAL 7 DAY);
END;
However, on your place I would solve the given problem with a simple cron script. The reasons to do this is simple: it's easier to maintain the code, no ugly SQL workarounds, integrates smoothly with your system.
This should do the trick.
DELETE FROM messages WHERE date < (CURDATE() - INTERVAL 7 DAY);
For those out there who are on a shared hosting, like 1and1's, and can't create events, an alternative is to use webcron
You just need to tell webcron the url of the php script you'd like to be run, and they'll trigger it for you at the intervals you want