You can create your own pseudo-temperature tables that can be accessed by several processes and connections.
The idea is to simply create memory tables, run operations, and clear later.
You can create a memory table with the following sql;
CREATE TABLE mydb.temp_32rfd293 ( id int(11) auto_increment, content varchar(50), PRIMARY KEY (`id`) ) ENGINE=MEMORY;
Do something useful, then lower it using
DROP TABLE temp_32rfd293:
Scheduled event to delete tables mydb.temp_% older than 1 day
You want to clear the temporary abandoned temporary table, you can create a scheduled event in mysql for this. If you decide to do this, consider using a dedicated schema for temporary tables to prevent accidental deletion.
Note. For this you need event_scheduler=ON in my.ini.
DELIMITER $$ CREATE EVENT `cleanup_custom_temps` ON SCHEDULE EVERY 1 DAY STARTS '2000-01-01 01:00:00' DO BEGIN --------------------------------------------------- -- Process to delete all tables with -- prefix 'temp_', and older than 1 day SET @tbls = ( SELECT GROUP_CONCAT(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME LIKE 'temp_%' AND CREATE_TIME < NOW() - INTERVAL 1 DAY ); SET @delStmt = CONCAT('DROP TABLE ', @tbls); PREPARE stmt FROM @delStmt; EXECUTE stmt; DEALLOCATE PREPARE stmt; --------------------------------------------------- END */$$ DELIMITER ;
harvey
source share