简体   繁体   English

MySQL Event Scheduler:存档早于1天的数据

[英]MySQL Event Scheduler: Archive data older than 1 day

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. 我有一个具有最新货币汇率的表,我创建了另一个表作为货币汇率的存档,我想首先将所有早于1个月的行插入存档,然后从最新货币汇率表中将其删除。

I have read about MySQL Event Scheduler which is like cron task from Unix. 我已经阅读了有关MySQL Event Scheduler的信息,它类似于Unix中的cron任务。 I was trying to create a Mysql Event Scheduler to do this task but i get a syntax error. 我试图创建一个Mysql Event Scheduler来执行此任务,但是出现语法错误。

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(); 每天1天在计划中创建事件存档,然后开始插入最新速率存档选择*从最新速率WHERE DATE(时间戳)<CURDATE(); FOR UPDATE; 更新;

DELETE FROM latestrate WHERE DATE(timestamp) < CURDATE(); 从最新的WHERE DATE(时间戳)<CURDATE();中删除; END 结束

And after i execute this commands in phpmyadmin i get this errors: 在phpmyadmin中执行此命令后,出现以下错误:

1064 - You have an error in your SQL syntax; 1064-您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 8 检查与您的MySQL服务器版本相对应的手册,以找到在第8行的''附近使用的正确语法

Anyone any has any idea where i am getting wrong? 任何人都知道我哪里错了吗?

Thanks in advance. 提前致谢。

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

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