set time_zone='+8:00';
set GLOBAL EVENT_SCHEDULER=1;
use zwxt;
drop EVENT IF EXISTS make_table_by_day;
DELIMITER $$
CREATE EVENT make_table_by_day
on SCHEDULE EVERY 2 day starts now()
on COMPLETION NOT PRESERVE ENABLE
DO
BEGIN
SET @target_tname='tbl_distribution_bg';
SET @target_day=DATE_FORMAT(now(),'%Y%m%d%H%i');
SET @sql_create_table=CONCAT('create table if not exists ',@target_tname,'_',@target_day,' like ',@target_tname);
PREPARE sql_create_table from @sql_create_table;
EXECUTE sql_create_table;
SET @sql_insertinto_select=CONCAT(' INSERT INTO ',@target_tname,'_',@target_day,' SELECT * FROM ',@target_tname);
PREPARE sql_insertinto_select from @sql_insertinto_select;
EXECUTE sql_insertinto_select;
DELETE FROM tbl_distribution_bg;
END $$
DELIMITER;