Search code examples
mysqldrop-table

MYSQL Table drop after x hours


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;