您好,登錄后才能下訂單哦!
#檢測(cè)事件是否開(kāi)啟
show variables like 'event_scheduler';
#開(kāi)啟事件(最好在my.init設(shè)置,因?yàn)橹貑⒑筮€會(huì)變回默認(rèn)值OFF)
set global event_scheduler = on;
#創(chuàng)建事件(從11月24號(hào)開(kāi)始每天執(zhí)行一次)
create EVENT eve_createTable ON SCHEDULE EVERY 1 DAY STARTS '2016-11-24 00:00:00' ON COMPLETION PRESERVE ENABLE DO CALL pro_createTable();
注:
1、ON
COMPLETION PRESERVE ENABLE 是創(chuàng)建此事件即開(kāi)始自動(dòng)執(zhí)行
2、SCHEDULE EVERY 1 DAY STARTS '2016-11-24 00:00:00' 從指定時(shí)間開(kāi)始每天執(zhí)行一次
#創(chuàng)建存儲(chǔ)過(guò)程(動(dòng)態(tài)表名)
CREATE PROCEDURE pro_createTable() BEGIN DECLARE str VARCHAR(20000); set str= CONCAT('CREATE TABLE member_network_',DATE_FORMAT(now(),'%Y%m%d'),'( `id` bigint(20) NOT NULL AUTO_INCREMENT , `member_id` bigint(20) NULL DEFAULT NULL , `host_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `serv_crc` varchar(2000) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL , `app_crc` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `sync_time` timestamp NULL DEFAULT NULL , `online_time` datetime NULL DEFAULT NULL , `type` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `up_stream_flux` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `down_stream_flux` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `total_stream_flux` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `line_no` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `url` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL , `action` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `sev_port` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `sor_port` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `protocol` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `regionCode` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `memo` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `policy` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `dns` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL , `idcard` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `client_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, PRIMARY KEY (`id`), INDEX `dept_type` (`regionCode`(255), `serv_crc`(255), `online_time`, `name`, `type`(255)) USING BTREE ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1 ROW_FORMAT=COMPACT '); SET @sqlstr=str; PREPARE stmt from @sqlstr; EXECUTE stmt; deallocate prepare stmt; END;
執(zhí)行時(shí)報(bào)錯(cuò),因?yàn)镃ONCAT拼接超過(guò)最大值;
#sql語(yǔ)句查看該參數(shù),修改并重啟mysql
show VARIABLES like '%max_allowed_packet%'; set global max_allowed_packet = 25600
mysql的前天、今天、后天
#2016-12-09 DATE_FORMAT(date_sub(curdate(),interval 1 day),'%Y%m%d') #2016-12-10 DATE_FORMAT(date_sub(curdate(),interval 0 day),'%Y%m%d') #2016-12-11 DATE_FORMAT(date_sub(curdate(),interval -1 day),'%Y%m%d')
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。