首頁 資料庫 mysql教程 MySQL定时执行存储过程

MySQL定时执行存储过程

Jun 07, 2016 pm 04:17 PM
mysql 儲存 定時 執行 過程

1,run--cmd-cd C:Program FilesMySQLMySQL Server 5.5bin 2, mysql -uXXXX -pXXXXXX 3, SHOW FULL PROCESSLISTG 4,设置sheduler SET GLOBAL event_scheduler = ON; SET @@global.event_scheduler = ON; SET GLOBAL event_scheduler = 1; SET @@global.event_

   1,run-->cmd->cd C:Program FilesMySQLMySQL Server 5.5bin

  2, mysql -uXXXX -pXXXXXX

  3, SHOW FULL PROCESSLISTG

  4,设置sheduler

  SET GLOBAL event_scheduler = ON;

  SET @@global.event_scheduler = ON;

  SET GLOBAL event_scheduler = 1;

  SET @@global.event_scheduler = 1;

  Similarly, any of these 4 statements can be used to turn off the Event Scheduler:

  SET GLOBAL event_scheduler = OFF;

  SET @@global.event_scheduler = OFF;

  SET GLOBAL event_scheduler = 0;

  SET @@global.event_scheduler = 0;

  5,create procedure

  -- --------------------------------------------------------------------------------

  -- Routine DDL

  -- Note: comments before and after the routine body will not be stored by the server

  -- --------------------------------------------------------------------------------

  DELIMITER $$

  CREATE DEFINER=`root`@`localhost` PROCEDURE `Get_Info_Every_Day`()

  BEGIN

  Declare pIntSumTotalAction int;

  Declare pIntSumNoduedate int;

  Declare pIntSumClosed int;

  Declare pIntSumForinfo int;

  Declare pIntSumOverdue int;

  Declare pIntSumTBDin1Week int;

  Declare pIntSumTBDafter1Week int;

  Declare pIntSumPendingJPMO int;

  Declare pIntSumEPS int;

  Declare pIntSumWCI int;

  Declare pIntSumOnTimeClosed int;

  Declare pIntTotal int; ##统计的时候所有的action items

  Declare strStatus varchar(40);

  Declare dDuedate datetime;

  Declare dClosedDate datetime;

  Declare nOverdue int;

  Declare nCountOnTime int; ##nIsOnTime count(*)数量

  declare fetchSeqOk boolean; ## define the flag for loop judgement

  /*

  Declare my_cursor cursor for select b.status,b.duedate,b.closedate,datediff(now(),b.duedate) as overdue,

  b.fk_actionitem from actionitem a,actionitemdetail b where a.id_actionitem=b.fk_actionitem and a.finishdate=0

  and status'forinfo' and (actionby like '%WEC%' or actionby like '%Consortium%' );

  */

  Declare my_cursor cursor for select b.status,b.duedate,b.closedate,datediff(now(),b.duedate) as overdue

  from actionitem a,actionitemdetail b where a.id_actionitem=b.fk_actionitem and a.finishdate=0

  and status'forinfo' and (actionby like '%WEC%' or actionby like '%Consortium%' );

  Declare my_cursor2 cursor for select cast(count(*) as UNSIGNED) as lnOnTimeClosedAI from actionitemdetail

  where datediff(now(),duedate)=0

  and (actionby like '%WEC%' or actionby like '%Consortium%' )

  and status='Closed' and datediff(closedate,duedate)

  declare continue handler for not found set fetchSeqOk = true;

  set pIntSumTotalAction=0;

  set pIntSumNoduedate=0;

  set pIntSumClosed=0;

  set pIntSumForinfo=0;

  set pIntSumOverdue=0;

  set pIntSumTBDin1Week=0;

  set pIntSumTBDafter1Week=0;

  set pIntSumPendingJPMO=0;

  set pIntSumEPS=0;

  set pIntSumWCI=0;

  set fetchSeqOk = false;

  /*

  declare continue handler for NOT FOUND set fetchSeqOk = true;

#define the continue handler for not found flag

  set fetchSeqOk = false;

  open fetchSeqCursor;

  fetchSeqLoop:Loop

  fetch fetchSeqCursor into _seqname, _value;

  if fetchSeqOk then

  leave fetchSeqLoop;

  else

  select _seqname, _value;

  end if;

  end Loop;

  close fetchSeqCursor;

  */

  open my_cursor;

  fetchLoop:LOOP

  fetch my_cursor into strStatus,dDuedate,dClosedDate,nOverdue;

  if fetchSeqOk then

  leave fetchLoop;

  else

  if LOWER(strStatus)='open' then

  case nOverdue

  when isnull(nOverdue) then set pIntSumNoduedate=pIntSumNoduedate+1;

  when nOverdue>0 then set pIntSumOverdue=pIntSumOverdue+1 ;

  when nOverdue-7 then set pIntSumTBDin1Week=pIntSumTBDin1Week+1;

  else set pIntSumTBDafter1Week=pIntSumTBDafter1Week+1;

  end case;

  else

  case LOWER(strStatus)

  when 'closed' then set pIntSumClosed=pIntSumClosed+1;

  when 'forinfo' then set pIntSumForinfo=pIntSumForinfo+1;

  when 'pending jpmo' then set pIntSumPendingJPMO=pIntSumPendingJPMO+1;

  when 'escalated to pcc for support' then set pIntSumEPS=pIntSumEPS+1;

  when 'waiting for customer input' then set pIntSumWCI=pIntSumWCI+1;

  end case;

  end if;

  end if;

  End LOOP;

  close my_cursor;

  set pIntTotal=pIntSumTBDafter1Week+pIntSumOverdue+pIntSumTBDin1Week+

pIntSumNoduedate+pIntSumPendingJPMO+pIntSumEPS+pIntSumWCI+pIntSumClosed;

  /*** 统计从当前日期向前推7天的committed closed情况

  nCountOnTime 表示count of on time closed number

  */

  set fetchSeqOk = false;

  open my_cursor2;

  my_loop:Loop

  fetch my_cursor2 into nCountOnTime;

  if fetchSeqOk then

  leave my_loop;

  else

  set pIntSumOnTimeClosed=nCountOnTime;

  end if;

  end Loop;

  close my_cursor2;

  insert into mytest(testdate)value(now());

  insert into daily_statistic(Total,Open,overdue,DueWithin7Days,PTP,NoDueDate,PendingJPMO,EPS,WCI,Closed)

  values(pIntTotal,pIntSumTBDafter1Week,pIntSumOverdue,pIntSumTBDin1Week,

pIntSumOnTimeClosed,pIntSumNoduedate,

  pIntSumPendingJPMO,pIntSumEPS,pIntSumWCI,pIntSumClosed);

  /*

  insert into daily_statistic(Total,Open,overdue,DueWithin7Days,PTP,NoDueDate,PendingJPMO,EPS,WCI,Closed)values

  (pIntTotal,pIntSumTBDafter1Week,pIntSumOverdue,pIntSumTBDin1Week,10,pIntSumNoduedate,

  pIntSumPendingJPMO,pIntSumEPS,pIntSumWCI,pIntSumClosed);

  */

  END

  6,create event

  use cddl;

  DROP EVENT IF EXISTS e_statistics_daily;

  CREATE EVENT e_statistics_daily

  ON SCHEDULE EVERY 1 Day

  STARTS '2013-10-18 16:45:00'

  on completion preserve

  DO CALL Get_Info_Every_Day();

  7, testing whether it is having the value or not

  select * from daily_statistic;

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1666
14
CakePHP 教程
1425
52
Laravel 教程
1324
25
PHP教程
1272
29
C# 教程
1251
24
laravel入門實例 laravel入門實例 Apr 18, 2025 pm 12:45 PM

Laravel 是一款 PHP 框架,用於輕鬆構建 Web 應用程序。它提供一系列強大的功能,包括:安裝: 使用 Composer 全局安裝 Laravel CLI,並在項目目錄中創建應用程序。路由: 在 routes/web.php 中定義 URL 和處理函數之間的關係。視圖: 在 resources/views 中創建視圖以呈現應用程序的界面。數據庫集成: 提供與 MySQL 等數據庫的開箱即用集成,並使用遷移來創建和修改表。模型和控制器: 模型表示數據庫實體,控制器處理 HTTP 請求。

MySQL和PhpMyAdmin:核心功能和功能 MySQL和PhpMyAdmin:核心功能和功能 Apr 22, 2025 am 12:12 AM

MySQL和phpMyAdmin是強大的數據庫管理工具。 1)MySQL用於創建數據庫和表、執行DML和SQL查詢。 2)phpMyAdmin提供直觀界面進行數據庫管理、表結構管理、數據操作和用戶權限管理。

MySQL與其他編程語言:一種比較 MySQL與其他編程語言:一種比較 Apr 19, 2025 am 12:22 AM

MySQL与其他编程语言相比,主要用于存储和管理数据,而其他语言如Python、Java、C 则用于逻辑处理和应用开发。MySQL以其高性能、可扩展性和跨平台支持著称,适合数据管理需求,而其他语言在各自领域如数据分析、企业应用和系统编程中各有优势。

解決數據庫連接問題:使用minii/db庫的實際案例 解決數據庫連接問題:使用minii/db庫的實際案例 Apr 18, 2025 am 07:09 AM

在開發一個小型應用時,我遇到了一個棘手的問題:需要快速集成一個輕量級的數據庫操作庫。嘗試了多個庫後,我發現它們要么功能過多,要么兼容性不佳。最終,我找到了minii/db,這是一個基於Yii2的簡化版本,完美地解決了我的問題。

laravel框架安裝方法 laravel框架安裝方法 Apr 18, 2025 pm 12:54 PM

文章摘要:本文提供了詳細分步說明,指導讀者如何輕鬆安裝 Laravel 框架。 Laravel 是一個功能強大的 PHP 框架,它 упростил 和加快了 web 應用程序的開發過程。本教程涵蓋了從系統要求到配置數據庫和設置路由等各個方面的安裝過程。通過遵循這些步驟,讀者可以快速高效地為他們的 Laravel 項目打下堅實的基礎。

解決MySQL模式問題:TheliaMySQLModesChecker模塊的使用體驗 解決MySQL模式問題:TheliaMySQLModesChecker模塊的使用體驗 Apr 18, 2025 am 08:42 AM

在使用Thelia開發電商網站時,我遇到了一個棘手的問題:MySQL模式設置不當,導致某些功能無法正常運行。經過一番探索,我找到了一個名為TheliaMySQLModesChecker的模塊,它能夠自動修復Thelia所需的MySQL模式,徹底解決了我的困擾。

MySQL:結構化數據和關係數據庫 MySQL:結構化數據和關係數據庫 Apr 18, 2025 am 12:22 AM

MySQL通過表結構和SQL查詢高效管理結構化數據,並通過外鍵實現表間關係。 1.創建表時定義數據格式和類型。 2.使用外鍵建立表間關係。 3.通過索引和查詢優化提高性能。 4.定期備份和監控數據庫確保數據安全和性能優化。

MySQL:解釋的關鍵功能和功能 MySQL:解釋的關鍵功能和功能 Apr 18, 2025 am 12:17 AM

MySQL是一個開源的關係型數據庫管理系統,廣泛應用於Web開發。它的關鍵特性包括:1.支持多種存儲引擎,如InnoDB和MyISAM,適用於不同場景;2.提供主從復制功能,利於負載均衡和數據備份;3.通過查詢優化和索引使用提高查詢效率。

See all articles