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

Was it helpful?

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:

  1. Move uploaded file to "incoming" directory
  2. Parse first few bytes of CSV to determine number of columns and additional data you need
  3. Let the user assign stuff
  4. Read CSV file to DB in the way your application needs it
  5. 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
scroll top