MySQL Event Scheduler: Archive data older than 1 day

264 Views Asked by At

i have a table with the latest currency rates, and i created another table as archive for the currency rates, and i want to firstly insert all rows that are older than 1 month to the archive and then delete it from the latest currency rates table.

I have read about MySQL Event Scheduler which is like cron task from Unix. I was trying to create a Mysql Event Scheduler to do this task but i get a syntax error.

The code is this:

CREATE EVENT archivate ON SCHEDULE EVERY 1 DAY DO BEGIN INSERT INTO latestrate_archive SELECT * FROM latest_rate WHERE DATE(timestamp) < CURDATE(); FOR UPDATE;

DELETE FROM latestrate WHERE DATE(timestamp) < CURDATE(); END

And after i execute this commands in phpmyadmin i get this errors:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 8

Anyone any has any idea where i am getting wrong?

Thanks in advance.

0

There are 0 best solutions below