我正在一个数据库驱动的网站上工作,而且我正在使用WAMP,如果可以使用mysql自动从下表中删除一行registrationDate老了 - 例如 - 一个月?
谢谢
ID | Name | registrationDate
1 | client1 | 2017-05-09 05:23:16
2 | client2 | 2017-05-11 12:13:30
答案 0 :(得分:0)
您可以使用例如:
CREATE EVENT deleteEachMonth
ON SCHEDULE EVERY 1 DAY STARTS '2017-05-01 00:00:00'
-- !!! no *END*: will continue until you explicitly drop the event
DO
DELETE FROM my_table WHERE my_date < DATE_SUB(curdate(), INTERVAL 1 MONTH);
在你的情况下
CREATE EVENT deleteEachMonth
ON SCHEDULE EVERY 1 DAY STARTS '2017-05-01 00:00:00'
DO
DELETE FROM client WHERE registrationDate < DATE_SUB(curdate(), INTERVAL 1 MONTH)