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;
,
핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











빅 데이터 구조 처리 기술: 청킹(Chunking): 데이터 세트를 분할하고 청크로 처리하여 메모리 소비를 줄입니다. 생성기: 전체 데이터 세트를 로드하지 않고 데이터 항목을 하나씩 생성하므로 무제한 데이터 세트에 적합합니다. 스트리밍: 파일을 읽거나 결과를 한 줄씩 쿼리하므로 대용량 파일이나 원격 데이터에 적합합니다. 외부 저장소: 매우 큰 데이터 세트의 경우 데이터를 데이터베이스 또는 NoSQL에 저장합니다.

선형 복잡성에서 로그 복잡성까지 조회 시간을 줄이는 인덱스를 구축하여 MySQL 쿼리 성능을 최적화할 수 있습니다. SQL 삽입을 방지하고 쿼리 성능을 향상하려면 PREPAREDStatements를 사용하세요. 쿼리 결과를 제한하고 서버에서 처리되는 데이터의 양을 줄입니다. 적절한 조인 유형 사용, 인덱스 생성, 하위 쿼리 사용 고려 등 조인 쿼리를 최적화합니다. 쿼리를 분석하여 병목 현상을 식별하고, 캐싱을 사용하여 데이터베이스 로드를 줄이고, 오버헤드를 최소화합니다.

PHP에서 MySQL 데이터베이스를 백업하고 복원하는 작업은 다음 단계에 따라 수행할 수 있습니다. 데이터베이스 백업: mysqldump 명령을 사용하여 데이터베이스를 SQL 파일로 덤프합니다. 데이터베이스 복원: mysql 명령을 사용하여 SQL 파일에서 데이터베이스를 복원합니다.

MySQL 테이블에 데이터를 삽입하는 방법은 무엇입니까? 데이터베이스에 연결: mysqli를 사용하여 데이터베이스에 대한 연결을 설정합니다. SQL 쿼리 준비: 삽입할 열과 값을 지정하는 INSERT 문을 작성합니다. 쿼리 실행: query() 메서드를 사용하여 삽입 쿼리를 실행하면 확인 메시지가 출력됩니다.

MySQL 8.4(2024년 최신 LTS 릴리스)에 도입된 주요 변경 사항 중 하나는 "MySQL 기본 비밀번호" 플러그인이 더 이상 기본적으로 활성화되지 않는다는 것입니다. 또한 MySQL 9.0에서는 이 플러그인을 완전히 제거합니다. 이 변경 사항은 PHP 및 기타 앱에 영향을 미칩니다.

PHP에서 MySQL 저장 프로시저를 사용하려면: PDO 또는 MySQLi 확장을 사용하여 MySQL 데이터베이스에 연결합니다. 저장 프로시저를 호출하는 문을 준비합니다. 저장 프로시저를 실행합니다. 결과 집합을 처리합니다(저장 프로시저가 결과를 반환하는 경우). 데이터베이스 연결을 닫습니다.

PHP를 사용하여 MySQL 테이블을 생성하려면 다음 단계가 필요합니다. 데이터베이스에 연결합니다. 데이터베이스가 없으면 작성하십시오. 데이터베이스를 선택합니다. 테이블을 생성합니다. 쿼리를 실행합니다. 연결을 닫습니다.

Oracle 데이터베이스와 MySQL은 모두 관계형 모델을 기반으로 하는 데이터베이스이지만 호환성, 확장성, 데이터 유형 및 보안 측면에서 Oracle이 우수하고, MySQL은 속도와 유연성에 중점을 두고 중소 규모 데이터 세트에 더 적합합니다. ① Oracle은 광범위한 데이터 유형을 제공하고, ② 고급 보안 기능을 제공하고, ③ 엔터프라이즈급 애플리케이션에 적합하고, ① MySQL은 NoSQL 데이터 유형을 지원하고, ② 보안 조치가 적고, ③ 중소 규모 애플리케이션에 적합합니다.
