欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

MySQL定时创建表的SQL语句_MySQL

程序员文章站 2022-05-19 09:12:28
...
bitsCN.com
MySQL定时创建表的SQL语句 -- 查看事件计划SELECT @@event_scheduler -- 打开事件计划 SET GLOBAL event_scheduler = 1 -- 存储过程,每月创建一张表CREATE PROCEDURE create_table()BEGIN declare str_date varchar(16);SET str_date = date_format(now(),"%Y%m"); SET @sqlcmd1 = CONCAT('CREATE TABLE db_mail_message_',str_date,"(apptaskid varchar(100) NOT NULL,taskname varchar(200) NOT NULL,appsenduid varchar(200) NOT NULL,appreceiveuid varchar(100) NOT NULL,sendtime varchar(50) NOT NULL,handletime varchar(50) NOT NULL,url varchar(500) NOT NULL,remark varchar(500) NOT NULL,endtime varchar(50) NOT NULL,imapuid varchar(100) NOT NULL,addstatus int(1) NOT NULL DEFAULT '0',readstatus int(1) NOT NULL DEFAULT '0',deletestatus int(1) NOT NULL DEFAULT '0',completestatus int(1) NOT NULL DEFAULT '0',PRIMARY KEY (apptaskid),KEY db_imapuid_index (imapuid)) ENGINE=MyISAM DEFAULT CHARSET=utf8;");PREPARE p1 FROM @sqlcmd1;EXECUTE p1;DEALLOCATE PREPARE p1;END-- 创建事件:每隔一秒自动调用存储过程CREATE EVENT IF NOT EXISTS e_testON SCHEDULE EVERY 1 SECONDON COMPLETION PRESERVEDO CALL test(); -- 创建事件:每月1号1点自动调用存储过程(未测试)CREATE EVENT if not exists e_test on schedule every 1 MONTH STARTS DATE_ADD(DATE_ADD(DATE_SUB(CURDATE(),INTERVAL DAY(CURDATE())-1 DAY), INTERVAL 1 MONTH),INTERVAL 1 HOUR) on completion preserve do call test();-- 开启事件alter event e_test ON COMPLETION PRESERVE ENABLE;-- 关闭事件alter event e_test ON COMPLETION PRESERVE DISABLE; bitsCN.com
相关标签: 计划