蓝海航行家
发布于

MySQL 事件未执行

尝试设置一个事件,将 table Daily_Prices 的状态复制到 Price_History 表中。

事件代码如下:

  CREATE EVENT CopyTodayPrices
ON SCHEDULE EVERY 1 DAY
STARTS '2024-08-13 20:25:00'
ON COMPLETION NOT PRESERVE
ENABLE
DO
BEGIN
    -- Ignore if prices are old (if the unique index throws an error)
    INSERT IGNORE INTO Prices_History (`Kreditorennr`, `Bar Code`, `Tagespreis`, `Preis vom`)
    SELECT `Kreditorennr`, `Bar Code`, `Tagespreis`, `Preis vom`
    FROM Daily_Prices;
END;

它不会在表Price_History中插入任何行。

在事件应该运行并且成功插入所有行之后,我尝试在 DBeaver 中将 BEGIN 和 END 之间的代码作为查询手动运行。

事件调度程序的工作原理是:

  > SHOW PROCESSLIST;
|Id |User           |Host                |db    |Command|Time |State                      |Info                                                                          |
|---|---------------|--------------------|------|-------|-----|---------------------------|------------------------------------------------------------------------------|
|5  |event_scheduler|localhost           |      |Daemon |1,597|Waiting for next activation|                                                                              |

而且该活动似乎也被安排好了:

  SHOW EVENTS;
  |Db    |Name           |Definer|Time zone|Type     |Execute at|Interval value|Interval field|Starts             |Ends|Status |Originator|character_set_client|collation_connection|Database Collation|
|------|---------------|-------|---------|---------|----------|--------------|--------------|-------------------|----|-------|----------|--------------------|--------------------|------------------|
|nocodb|CopyTodayPrices|root@% |SYSTEM   |RECURRING|          |1             |DAY           |2024-08-13 20:25:00|    |ENABLED|1         |utf8mb4             |utf8mb4_0900_ai_ci  |utf8mb4_0900_ai_ci|
浏览 (5)
点赞
收藏
1条评论
Klustron小助手
在 comment 中Price_History,在 query 中Prices_History。使用复数 priceS。
点赞
评论