MYSQL Table drop after x hours
-
13-06-2021 - |
Question
Is it possible to write extra code into a mysql table creation that will make it drop itself after X amount of time? Like a temp table, but it will last longer.
I need to create tables for temporary tasks, but i need them to last longer than a session
Solution
CREATE EVENT myevt
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
DO
DROP TABLE IF EXISTS MyTable;
OTHER TIPS
In your case with the CSV files, I would advise against creating a database table during your setup process, since that puts unecessary stress on your DBMS. A better way to do this would be:
- Move uploaded file to "incoming" directory
- Parse first few bytes of CSV to determine number of columns and additional data you need
- Let the user assign stuff
- Read CSV file to DB in the way your application needs it
- Delete file
In order to cleanup the CSV files, you can use a cronjob to delete old files: find /dir/with/csv/files -type f -cmin +TIMEINMINUTES -delete
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow