How to AUTO update MySQL after timestamp field expierd(如何在时间戳字段过期后自动更新 MySQL)
问题描述
如何在过期时间戳时自动更新或插入 MySQL?
How do I automate MySQL Update or Insert upon expire timestamp?
所以假设时间戳是 2013-06-30 20:10:00,我想在通过该日期和时间后自动更新 MySQL DB,所以今天 2013-06-03 20:10:00.
So let say timestamp is 2013-06-30 20:10:00 and I would like to auto update MySQL DB upon passing that date and time so today after 2013-06-03 20:10:00.
我想更新我的项目,但我的网站无法打开浏览器,所以我想我需要某种服务器触发器??我怎么做?非常感谢
I want to update my item, but I will not have browser open with my website, so I think so I need some kind of server trigger?? How do I do that? Many thanks
我有以下查询每 1 秒执行一次,但它不起作用:
I have following Query to execute every 1 second and it doesn't work:
CREATE EVENT e_second
    ON SCHEDULE
      EVERY 1 SECOND
    DO
UPDATE online_auctions.auction_status
   SET auction_status = 'ENDED' WHERE TIMESTAMP(auction_end_date) < (select now());
推荐答案
Use can be used for that
Use can use for that
- Mysql events(恕我直言,最佳人选)
 - cron 作业或 Windows 任务计划程序(如果您使用的是 Windows 平台)
 
- Mysql events (IMHO the best candidate)
 - cron job or Windows Task Scheduler (if you're on Windows platform)
 
如果您选择选项 1,您需要创建一个事件
If you go with option 1 you need to create an event
CREATE EVENT myevent 
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO 
UPDATE myschema.mytable 
   SET mycol = mycol + 1;
使用 SHOW PROCESSLIST 检查是否启用了事件调度程序.如果它是 ON,您应该看到用户event_scheduler"的进程Daemon".如果当前未启用调度程序,请使用 SET GLOBAL event_scheduler = ON; 启用它.有关配置事件调度程序的更多信息此处.
Use SHOW PROCESSLIST to check if event scheduler is enabled. If it's ON you should see a process "Daemon" by user "event_scheduler". Use SET GLOBAL event_scheduler = ON; to enable the scheduler if it's currently not enabled. More on configuring event scheduler here.
如果您想查看架构中的事件
If you want to see events that you've in your schema
SHOW EVENTS;
UPDATE 你的更新语句应该看起来像
UPDATE Your update statement should look like
UPDATE online_auctions 
   SET auction_status = 'ENDED' 
 WHERE auction_end_date < NOW();
这是SQLFiddle 演示
Here is SQLFiddle demo
这篇关于如何在时间戳字段过期后自动更新 MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在时间戳字段过期后自动更新 MySQL
				
        
 
            
        - 导入具有可变标题的 Excel 文件 2021-01-01
 - 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
 - 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
 - 更改自动增量起始编号? 2021-01-01
 - 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
 - SQL 临时表问题 2022-01-01
 - 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
 - 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
 - 在SQL中,如何为每个组选择前2行 2021-01-01
 - 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
 
						
						
						
						
						
				
				
				
				