mysql 定时任务 EVENT
show variables like 'event_scheduler';
set global event_scheduler = on; -- 登录root 进行设置
CREATE EVENT gmp_remainDays_event
ON SCHEDULE
EVERY 1 Minute
ON COMPLETION PRESERVE
DO
BEGIN
update gmp_check_info set remain_days= datediff(now(),begin_date);
update gmp_verify_info set remain_days= datediff(now(),begin_date);
update gmp_maintain_info set remain_days= datediff(now(),begin_date);
end;
use gmp;
show events;
DROP EVENT IF EXISTS remainDays_check_even1;
----------------------
[root@VM-4-3-centos ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 27620
Server version: 5.7.40-log Source distribution
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like 'event_scheduler';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| event_scheduler | OFF |
+-----------------+-------+
1 row in set (0.01 sec)
mysql> set global event_scheduler = on;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like 'event_scheduler';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| event_scheduler | ON |
+-----------------+-------+
1 row in set (0.00 sec)
mysql> drop event if exists remainDays_check_event;
ERROR 1046 (3D000): No database selected
mysql> select gmp;
ERROR 1054 (42S22): Unknown column 'gmp' in 'field list'
mysql> use gmp;
Database changed
mysql> drop event if exists remainDays_check_event;
Query OK, 0 rows affected (0.00 sec)
mysql> 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 |
+-----+-------------------------+-----------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+
| gmp | remainDays_check_event1 | gmpuser@% | SYSTEM | RECURRING | NULL | 1 | MINUTE | 2024-07-19 15:15:48 | NULL | ENABLED | 1 | utf8mb4 | utf8mb4_general_ci | utf8mb4_general_ci |
| gmp | remainDays_check_event2 | gmpuser@% | SYSTEM | RECURRING | NULL | 1 | MINUTE | 2024-07-19 15:26:24 | NULL | ENABLED | 1 | utf8mb4 | utf8mb4_general_ci | utf8mb4_general_ci |
+-----+-------------------------+-----------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+
2 rows in set (0.00 sec)
mysql> drop event if exists remainDays_check_event1;
Query OK, 0 rows affected (0.01 sec)
mysql> 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 |
+-----+-------------------------+-----------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+
| gmp | remainDays_check_event2 | gmpuser@% | SYSTEM | RECURRING | NULL | 1 | MINUTE | 2024-07-19 15:26:24 | NULL | ENABLED | 1 | utf8mb4 | utf8mb4_general_ci | utf8mb4_general_ci |
+-----+-------------------------+-----------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+
1 row in set (0.00 sec)
mysql> drop event if exists remainDays_check_event2;
Query OK, 0 rows affected (0.00 sec)
mysql> 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 |
+-----+------------------+-----------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+
| gmp | check_remainDays | gmpuser@% | SYSTEM | RECURRING | NULL | 1 | MINUTE | 2024-07-19 15:35:40 | NULL | ENABLED | 1 | utf8mb4 | utf8mb4_general_ci | utf8mb4_general_ci |
+-----+------------------+-----------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+
1 row in set (0.00 sec)
mysql> drop event if exists check_remainDays;
Query OK, 0 rows affected (0.00 sec)
mysql> show events;
Empty set (0.00 sec)
mysql>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具