You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MariaDB创建定时事件报#1064语法错误,求排查解决

Fixing the #1064 Syntax Error in Your MariaDB Scheduled Event

Hey there! That syntax error you're seeing near END is a classic gotcha when working with multi-statement event blocks. Let me break down what's going wrong and how to fix it.

The Root Cause

By default, MySQL/MariaDB uses the semicolon (;) as the statement delimiter. When you write a BEGIN...END block with multiple SQL statements inside, the database sees the first semicolon (after your SET statement) as the end of the entire CREATE EVENT command. The rest of the code (from UPDATE onward) then becomes invalid syntax.

The Fix: Temporary Delimiter Change

You need to temporarily switch to a different delimiter (like // or $$) so the database treats the entire BEGIN...END block as a single statement. Here's your corrected code:

-- Temporarily change the delimiter to //
DELIMITER //

CREATE DEFINER=`root`@`localhost` EVENT `start_game` 
ON SCHEDULE EVERY 3 MINUTE 
STARTS '2018-05-05 05:50:07' 
ON COMPLETION PRESERVE 
DISABLE 
DO 
BEGIN 
    SET @game_id = (SELECT id FROM tbl_game WHERE game_status=0 ORDER BY id ASC LIMIT 1); 
    UPDATE tbl_game SET game_status = 1 WHERE id = @game_id; 
END //

-- Switch back to the default semicolon delimiter
DELIMITER ;

Quick Additional Checks

  • Make sure the event scheduler is enabled: Run SHOW VARIABLES LIKE 'event_scheduler'; – if the value is OFF, enable it with SET GLOBAL event_scheduler = ON; (you might need to add this to your my.cnf/my.ini to keep it enabled after restart).
  • Verify permissions: The root@localhost user should have the EVENT privilege to create scheduled events. If not, grant it with GRANT EVENT ON *.* TO 'root'@'localhost';.

That should resolve the syntax error and get your event created properly!

内容的提问来源于stack exchange,提问作者Gurpreet Singh Matharu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:45:42