zoukankan      html  css  js  c++  java
  • mysql存储过程和定时调用

    1、创建存储过程

    1 create procedure proc_name()
    2 begin
    3 sql;
    4 end

    sql为定时值执行的代码,比如,定时向表里插入当前时间:INSERT into table(times) VALUES(NOW());;然后通过事件调度来定时执行该存储过程。

    2、创建触发事件

    1 create event if not exists event_name
    2 on schedule every 30 second
    3 on completion preserve
    4 do call proc_name()

    创建一个事件调度,在该事件调度完成后,每30秒执行调用存储过程一次。若只想让存储过程在某个时间只执行一次,则把preserve改为not preserve。

    3、查看event是否开启

    1 show variables like '%sche%'

    4、将事件计划开启

    1 set global event_scheduler=1;

    全局事件调度开关,1为开,0为关。

    5、开启事件任务

    1 alter event event_name on completion preserve enable;

    打开指定的事件调度开关

    6、关闭事件任务

    1 alter event event_name on completion preserve disable;

    关闭指定的事件调度开关

    7、查看数据库所有的存储过程

    1 SELECT * FROM mysql.proc

    查看数据库的所有存储过程,在mysql安装完后,就默认安装有一个叫mysql的数据库,里面有一个表叫proc,通过查看这个表也可以查询数据库的所有存储过程。

    8、查看数据库里所有的存储过程+内容

    1 show procedure status;

    9、查看存储过程或函数的创建代码

    1 show create procedure you_proc_name;

    10、删除存储过程

    1 drop procedure proc_name;
  • 相关阅读:
    Iterator与 Enumeration
    多态性理解
    django---路由层
    django常用模块汇总
    django初识
    python常见模块
    python PEP8规范
    logging模块
    mysql一些了解的名词
    python 链接 mysql数据库
  • 原文地址:https://www.cnblogs.com/TimeStory/p/4201770.html
Copyright © 2011-2022 走看看