MySQL how to make value expire?

后端 未结 3 1126
无人共我
无人共我 2021-01-07 06:24

So I\'m currently designing a Forgot Password feature for a website. Basically, when the user clicks forgot password it sends them an email with a reset token. I want the re

3条回答
  •  甜味超标
    2021-01-07 07:00

    I'd use MySQL Events for that:

    CREATE EVENT IF NOT EXISTS `dbName`.`eventName`
    ON SCHEDULE
    EVERY 1 DAY // or 1 HOUR
    COMMENT 'Description'
    DO
    BEGIN
    
    DELETE FROM `dbName`.`TableName` WHERE `expireDateCol` < NOW();
    
    END
    

    and enable the MySQL Event Scheduler , see original source.

    source: https://stackoverflow.com/a/24568566/2069181

提交回复
热议问题