搜尋
首頁資料庫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
mysql:blob和其他無-SQL存儲,有什麼區別?mysql:blob和其他無-SQL存儲,有什麼區別?May 13, 2025 am 12:14 AM

mysql'sblobissuitableForStoringBinaryDataWithInareLationalDatabase,而ilenosqloptionslikemongodb,redis和calablesolutionsolutionsolutionsoluntionsoluntionsolundortionsolunsonstructureddata.blobobobissimplobisslowdeperformberbutslowderformandperformancewithlararengedata;

mySQL添加用戶:語法,選項和安全性最佳實踐mySQL添加用戶:語法,選項和安全性最佳實踐May 13, 2025 am 12:12 AM

toaddauserinmysql,使用:createUser'username'@'host'Indessify'password'; there'showtodoitsecurely:1)choosethehostcarecarefullytocon trolaccess.2)setResourcelimitswithoptionslikemax_queries_per_hour.3)usestrong,iniquepasswords.4)Enforcessl/tlsconnectionswith

MySQL:如何避免字符串數據類型常見錯誤?MySQL:如何避免字符串數據類型常見錯誤?May 13, 2025 am 12:09 AM

toAvoidCommonMistakeswithStringDatatatPesInMysQl,CloseStringTypenuances,chosethirtightType,andManageEngencodingAndCollat​​ionsEttingSefectery.1)usecharforfixed lengengtrings,varchar forvariable-varchar forbariaible length,andtext/blobforlargerdataa.2 seterters seterters seterters

mySQL:字符串數據類型和枚舉?mySQL:字符串數據類型和枚舉?May 13, 2025 am 12:05 AM

mysqloffersechar,varchar,text,and denumforstringdata.usecharforfixed Lengttrings,varcharerforvariable長度,文本forlarger文本,andenumforenforcingDataAntegrityWithaEtofValues。

mysql blob:如何優化斑點請求mysql blob:如何優化斑點請求May 13, 2025 am 12:03 AM

優化MySQLBLOB請求可以通過以下策略:1.減少BLOB查詢頻率,使用獨立請求或延遲加載;2.選擇合適的BLOB類型(如TINYBLOB);3.將BLOB數據分離到單獨表中;4.在應用層壓縮BLOB數據;5.對BLOB元數據建立索引。這些方法結合實際應用中的監控、緩存和數據分片,可以有效提升性能。

將用戶添加到MySQL:完整的教程將用戶添加到MySQL:完整的教程May 12, 2025 am 12:14 AM

掌握添加MySQL用戶的方法對於數據庫管理員和開發者至關重要,因為它確保數據庫的安全性和訪問控制。 1)使用CREATEUSER命令創建新用戶,2)通過GRANT命令分配權限,3)使用FLUSHPRIVILEGES確保權限生效,4)定期審計和清理用戶賬戶以維護性能和安全。

掌握mySQL字符串數據類型:varchar vs.文本與char掌握mySQL字符串數據類型:varchar vs.文本與charMay 12, 2025 am 12:12 AM

chosecharforfixed-lengthdata,varcharforvariable-lengthdata,andtextforlargetextfield.1)chariseffity forconsistent-lengthdatalikecodes.2)varcharsuitsvariable-lengthdatalikenames,ballancingflexibilitibility andperformance.3)

MySQL:字符串數據類型和索引:最佳實踐MySQL:字符串數據類型和索引:最佳實踐May 12, 2025 am 12:11 AM

在MySQL中處理字符串數據類型和索引的最佳實踐包括:1)選擇合適的字符串類型,如CHAR用於固定長度,VARCHAR用於可變長度,TEXT用於大文本;2)謹慎索引,避免過度索引,針對常用查詢創建索引;3)使用前綴索引和全文索引優化長字符串搜索;4)定期監控和優化索引,保持索引小巧高效。通過這些方法,可以在讀取和寫入性能之間取得平衡,提升數據庫效率。

See all articles

熱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

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

熱門文章

熱工具

SecLists

SecLists

SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具