Mysql定時任務:每兩天執行一次

set time_zone='+8:00';sql

 

set GLOBAL EVENT_SCHEDULER=1;get

use zwxt;io

drop EVENT IF EXISTS make_table_by_day;table

DELIMITER $$select

CREATE EVENT make_table_by_day
on SCHEDULE EVERY 2 day starts now()im

on COMPLETION NOT PRESERVE ENABLEtab

DOdi

BEGINmake

SET @target_tname='tbl_distribution_bg';time

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; 

相關文章
相關標籤/搜索