搜尋
首頁資料庫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
說明InnoDB重做日誌和撤消日誌的作用。說明InnoDB重做日誌和撤消日誌的作用。Apr 15, 2025 am 12:16 AM

InnoDB使用redologs和undologs確保數據一致性和可靠性。 1.redologs記錄數據頁修改,確保崩潰恢復和事務持久性。 2.undologs記錄數據原始值,支持事務回滾和MVCC。

在解釋輸出(類型,鍵,行,額外)中要查找的關鍵指標是什麼?在解釋輸出(類型,鍵,行,額外)中要查找的關鍵指標是什麼?Apr 15, 2025 am 12:15 AM

EXPLAIN命令的關鍵指標包括type、key、rows和Extra。 1)type反映查詢的訪問類型,值越高效率越高,如const優於ALL。 2)key顯示使用的索引,NULL表示無索引。 3)rows預估掃描行數,影響查詢性能。 4)Extra提供額外信息,如Usingfilesort提示需要優化。

在解釋中使用臨時狀態以及如何避免它是什麼?在解釋中使用臨時狀態以及如何避免它是什麼?Apr 15, 2025 am 12:14 AM

Usingtemporary在MySQL查詢中表示需要創建臨時表,常見於使用DISTINCT、GROUPBY或非索引列的ORDERBY。可以通過優化索引和重寫查詢避免其出現,提升查詢性能。具體來說,Usingtemporary出現在EXPLAIN輸出中時,意味著MySQL需要創建臨時表來處理查詢。這通常發生在以下情況:1)使用DISTINCT或GROUPBY時進行去重或分組;2)ORDERBY包含非索引列時進行排序;3)使用複雜的子查詢或聯接操作。優化方法包括:1)為ORDERBY和GROUPB

描述不同的SQL交易隔離級別(讀取未讀取,讀取,可重複的讀取,可序列化)及其在MySQL/InnoDB中的含義。描述不同的SQL交易隔離級別(讀取未讀取,讀取,可重複的讀取,可序列化)及其在MySQL/InnoDB中的含義。Apr 15, 2025 am 12:11 AM

MySQL/InnoDB支持四種事務隔離級別:ReadUncommitted、ReadCommitted、RepeatableRead和Serializable。 1.ReadUncommitted允許讀取未提交數據,可能導致臟讀。 2.ReadCommitted避免臟讀,但可能發生不可重複讀。 3.RepeatableRead是默認級別,避免臟讀和不可重複讀,但可能發生幻讀。 4.Serializable避免所有並發問題,但降低並發性。選擇合適的隔離級別需平衡數據一致性和性能需求。

MySQL與其他數據庫:比較選項MySQL與其他數據庫:比較選項Apr 15, 2025 am 12:08 AM

MySQL適合Web應用和內容管理系統,因其開源、高性能和易用性而受歡迎。 1)與PostgreSQL相比,MySQL在簡單查詢和高並發讀操作上表現更好。 2)相較Oracle,MySQL因開源和低成本更受中小企業青睞。 3)對比MicrosoftSQLServer,MySQL更適合跨平台應用。 4)與MongoDB不同,MySQL更適用於結構化數據和事務處理。

MySQL索引基數如何影響查詢性能?MySQL索引基數如何影響查詢性能?Apr 14, 2025 am 12:18 AM

MySQL索引基数对查询性能有显著影响:1.高基数索引能更有效地缩小数据范围,提高查询效率;2.低基数索引可能导致全表扫描,降低查询性能;3.在联合索引中,应将高基数列放在前面以优化查询。

MySQL:新用戶的資源和教程MySQL:新用戶的資源和教程Apr 14, 2025 am 12:16 AM

MySQL學習路徑包括基礎知識、核心概念、使用示例和優化技巧。 1)了解表、行、列、SQL查詢等基礎概念。 2)學習MySQL的定義、工作原理和優勢。 3)掌握基本CRUD操作和高級用法,如索引和存儲過程。 4)熟悉常見錯誤調試和性能優化建議,如合理使用索引和優化查詢。通過這些步驟,你將全面掌握MySQL的使用和優化。

現實世界Mysql:示例和用例現實世界Mysql:示例和用例Apr 14, 2025 am 12:15 AM

MySQL在現實世界的應用包括基礎數據庫設計和復雜查詢優化。 1)基本用法:用於存儲和管理用戶數據,如插入、查詢、更新和刪除用戶信息。 2)高級用法:處理複雜業務邏輯,如電子商務平台的訂單和庫存管理。 3)性能優化:通過合理使用索引、分區表和查詢緩存來提升性能。

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脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
4 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
4 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
4 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
1 個月前By尊渡假赌尊渡假赌尊渡假赌

熱工具

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

SublimeText3 Mac版

SublimeText3 Mac版

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

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能