mysql event 变量_mysql 中event的用法
二、適用范圍對(duì)于每隔一段時(shí)間就有固定需求的操作,如創(chuàng)建表,刪除數(shù)據(jù)等操作,可以使用event來(lái)處理。
例如:使用event在每月的1日凌晨1點(diǎn)自動(dòng)創(chuàng)建下個(gè)月需要使用的三張表。
三、使用權(quán)限
開(kāi)啟event :(1)執(zhí)行 SET GLOBAL event_scheduler = 1;(2)在mysql配置文件中設(shè)置:event_scheduler=ON
查看event :(1)SHOW VARIABLES LIKE 'event_scheduler'; (2)要求東八區(qū)? show variables like '%time_zone%';
eg:
早上5點(diǎn)往t_bb_register_loan中插入數(shù)據(jù)
create EVENT bb_register_loan_to_everyday
on SCHEDULE every 1 day starts? timestamp '2015-05-30 05:00:00'
do
insert into t_bb_register_loan(createTime,userId,nickName,realName,idCardNo,mobile,registerTime,inviterNickName,loanId,investAmount,investTime,qx,amount,redAmount,coupon,returnAmount)
select
NOW(),b.userid,b.nickName,b.realName,b.idCardNo,b.mobile,b.registerTime,(select u.nickname from user_main u where u.mobile=s.mobile),
a.loanid,a.investAmount,a.investTime,CONCAT(a.termCount,if(a.termUnit=1,'天',if(a.termUnit=2,'周','月'))),a.amount,a.red_money_amount,a.coupon,a.returnAmount
from user_main b
left join (
select a.loanid,c.title,c.termCount,c.termUnit,c.amount,c.openTime,c.fullTime,a.investAmount,a.investTime,a.investorUserId,a.red_money_amount,t.coupon,t.returnAmount
from loan_investor a,loan c,(select t.loanid,t.LOAN_INVESTOR_ID,r.coupon,r.returnAmount from trade t left join t_requestcouponrecord r on t.couponid=r.id where SERIAL_NUMBER like '05%' and t.TRADE_STATUS='SUCCESS'
)t
where? a.loanid = c.loanid and
a.loanid=t.loanid and a.id=t.LOAN_INVESTOR_ID and
a.investTime >DATE_FORMAT(SUBDATE(now(),interval 1 day),'%Y-%m-%d') and a.investTime
)a on a.investorUserId = b.userid
left join user_invited_code d on? b.userid=d.userid
left join(
select r.mobile,r.userid,IFNULL(recommendcode,r.mobile) code from t_recommendinfo r
) s on s.userid=b.userid
where? b.registerTime >=DATE_FORMAT(SUBDATE(now(),interval 1 day),'%Y-%m-%d') and b.registerTime
刪除event :?drop event if exists bb_register_loan_to_everyday;
查詢(xún):select * from mysql.event
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的mysql event 变量_mysql 中event的用法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: qt自定义含有拖动功能的窗口在点击窗口的
- 下一篇: SQL约束攻击