In MongoDB there is expireAfterSeconds index which deletes the object automatically after a certain amount of time. I was wondering if there is such a thing in MySQL?
Asked
Active
Viewed 1.6k times
1 Answers
20
No, you need to DELETE
the data when it's expired.
You can implement something similar by adding a DATETIME field and run a scheduled task in your operating system (a cronjob on Unix-like systems).
You can even schedule it directly in MySQL:

Community
- 1
- 1

Emil Vikström
- 90,431
- 16
- 141
- 175
-
In some newer MySQL versions you will be able to schedule events, see this anwser; http://stackoverflow.com/questions/19197486/mysql-record-that-would-subject-to-ttl/19400466#comment54034258_19400466 – Renato Gama Oct 13 '15 at 18:33
-
the first link is 404 – Ivan Vinogradov Jun 28 '19 at 13:13