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

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

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

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

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

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

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

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


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

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

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

Atom編輯器mac版下載
最受歡迎的的開源編輯器

Dreamweaver CS6
視覺化網頁開發工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能