简体   繁体   English

时间戳过期时,从数据库中删除登录数据MySQL

[英]Delete login data from database when timestamp expires MySQL

I have this database: 我有这个数据库:

login_id -> AI, INT, PK
login_token -> VARCHAR(255)
login_userId -> VARCHAR(255)
login_expires -> VARCHAR(255)

login_expires is a UNIX timestamp. login_expires是UNIX时间戳。

The login_token will be bound to a cookie. login_token将绑定到cookie。 When the cookie expires, the row from the database with the login_token from the cookie should be deleted too. 当cookie过期时,数据库中带有cookie的login_token的行也应删除。

What's the easiest why to do this? 什么是最简单的原因?

With MySQL >= 5.1 you can use an event scheduler: 在MySQL> = 5.1的情况下,您可以使用事件调度程序:

CREATE EVENT expired
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 5 MINUTES
DO
   DELETE FROM your_table
   WHERE login_expires < NOW();

Read more about this in MySQL reference manual MySQL参考手册中阅读有关此内容的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM