mysql event 变量_mysql 中event的用法

二、适用范围对于每隔一段时间就有固定需求的操作,如创建表,删除数据等操作,可以使用event来处理。

例如:使用event在每月的1日凌晨1点自动创建下个月需要使用的三张表。

三、使用权限

开启event :(1)执行 SET GLOBAL event_scheduler = 1;(2)在mysql配置文件中设置:event_scheduler=ON

查看event :(1)SHOW VARIABLES LIKE 'event_scheduler'; (2)要求东八区  show variables like '%time_zone%';

eg:

早上5点往t_bb_register_loan中插入数据

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;

查询:select * from mysql.event

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值