我创建的EVENT基本上做了两件事:
SELECT
超过30天的行INSERT
进入achieve
表。DELETE
trends
表中超过30天的行。我分别测试了两个脚本,它们都工作正常,但是在将它们放入EVENT时出现了语法错误。
如果我只在活动正文中使用INSERT INTO
或DELETE
脚本,则会保存正常。
脚本是:
CREATE DEFINER=`root`@`localhost`
EVENT `trend_decayer` ON SCHEDULE EVERY 1 DAY
STARTS '2016-08-30 00:00:00' ON COMPLETION NOT PRESERVE ENABLE
COMMENT 'Decay trends that are older than 30 days'
DO
INSERT INTO `achieve`
SELECT *, FROM_UNIXTIME(`trends`.`timestamp`) AS `datetime`
FROM `trends`
WHERE `t`.`timestamp` < UNIX_TIMESTAMP(CAST(DATE_SUB(NOW(), INTERVAL 30 DAY) AS DATETIME))
ORDER BY `datetime` DESC;
DELETE
FROM `trends`
WHERE `timestamp` < UNIX_TIMESTAMP(CAST(DATE_SUB(NOW() , INTERVAL 30 DAY) AS DATETIME));
错误消息是:
MySQL said: #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
'INTO `achieve`
SELECT *, FROM_UNIXTIME(`timestamp`) AS `datetime` FR' at line 2`