Win下Mysql資料每日查詢匯出傳送方案

2021-07-08 14:54:50 字數 4299 閱讀 4417

1、資料處理的儲存過程

create definer=`datahs`@`%` procedure `p_kingr_sum_daily`(in `p_statistics_date` int)

begin

insert into datatest.kingr1

...........................

insert into datatest.kingr2

...........................

insert into datatest.kingr3

...........................

insert into datatest.kingr4

...........................

insert into datatest.kingr5

...........................

commit;

end

2、實現連續跑多天儲存過程(乙個月內)

create definer=`datahs`@`%` procedure `p_execproc_while`()

begin

declare i integer;

set i=20151201;

while i<=20151231 do

begin

call p_kingr_sum_daily(i);

set i=i+1;

end;

end while;

end

3、資料匯出目錄路徑

c:\data_dir>tree c:\data_dir\data-exp-daily /f

卷 windows 的資料夾 path 列表

卷序列號為 d4d2-8713

c:\data_dir\data-exp-daily

│ data_proc_script.bat

│ fetch_n_day_ago.bat

│ mydate.vbs

│└─kingr_data

kingr1_20151203.txt

kingr2_20151203.txt

kingr3_20151203.txt

kingr4_20151203.txt

kingr5_20151203.txt

4、獲取昨天日期的vbs指令碼

c:\data_dir\data-exp-daily>type mydate.vbs

createobject("scripting.filesystemobject").createtextfile("c:\data_dir\data-exp-daily\mydate.cmd").write "set mydate=" & datepart("yyyy",date - 1) & right("0" & datepart("m",date - 1), 2) & right("0" & datepart("d",date - 1),2)

5、測試昨天日期獲取正確與否指令碼

c:\data_dir\data-exp-daily>type fetch_n_day_ago.bat

@echo off

cscript c:\data_dir\data-exp-daily\mydate.vbs //nologo

call c:\data_dir\data-exp-daily\mydate.cmd

del c:\data_dir\data-exp-daily\mydate.cmd

echo on

@echo %mydate%

@echo off

pause

6、資料處理指令碼

c:\data_dir\data-exp-daily>type data_proc_script.bat

@echo off

cscript c:\data_dir\data-exp-daily\mydate.vbs //nologo

call c:\data_dir\data-exp-daily\mydate.cmd

del c:\data_dir\data-exp-daily\mydate.cmd

echo on

rem set formatdate=%mydate:~0,4%%mydate:~5,2%%mydate:~8,2%\

set formatdate=%mydate%

mysql -h120.55.189.188 -udatawarehouse -pdths2015 -e "delete from datatest.kingr1 where statistics_date=%formatdate%;"

mysql -h120.55.189.188 -udatawarehouse -pdths2015 -e "delete from datatest.kingr2 where statistics_date=%formatdate%;"

mysql -h120.55.189.188 -udatawarehouse -pdths2015 -e "delete from datatest.kingr3 where statistics_date=%formatdate%;"

mysql -h120.55.189.188 -udatawarehouse -pdths2015 -e "delete from datatest.kingr4 where statistics_date=%formatdate%;"

mysql -h120.55.189.188 -udatawarehouse -pdths2015 -e "delete from datatest.kingr5 where statistics_date=%formatdate%;"

mysql -h120.55.189.188 -udatawarehouse -pdths2015 -e "call datahouse.p_kingr_sum_daily(%formatdate%);"

mysql -h120.55.189.188 -udatawarehouse -pdths2015 -e "select * from datatest.kingr1 where statistics_date=%formatdate%;" > c:\data_dir\data-exp-daily\kingr_data\kingr1_%formatdate%.txt

mysql -h120.55.189.188 -udatawarehouse -pdths2015 -e "select * from datatest.kingr2 where statistics_date=%formatdate%;" > c:\data_dir\data-exp-daily\kingr_data\kingr2_%formatdate%.txt

mysql -h120.55.189.188 -udatawarehouse -pdths2015 -e "select * from datatest.kingr3 where statistics_date=%formatdate%;" > c:\data_dir\data-exp-daily\kingr_data\kingr3_%formatdate%.txt

mysql -h120.55.189.188 -udatawarehouse -pdths2015 -e "select * from datatest.kingr4 where statistics_date=%formatdate%;" > c:\data_dir\data-exp-daily\kingr_data\kingr4_%formatdate%.txt

mysql -h120.55.189.188 -udatawarehouse -pdths2015 -e "select * from datatest.kingr5 where statistics_date=%formatdate%;" > c:\data_dir\data-exp-daily\kingr_data\kingr5_%formatdate%.txt

7、設定計畫任務

將data_proc_script.bat執行指令碼在任務計畫中設定成每天定時執行。

8、後續處理

將匯出的資料檔案以郵件方式傳送出去;當然更深一步,可以設定

郵件自動傳送。

Win下忘記mySql密碼

真粗心!1.關閉正在執行的mysql。2.開啟dos視窗,轉到mysql bin目錄。3.輸入 mysqld nt skip grant tables 或者mysqld skip grant tables 回車。理想情況是沒有出現提示資訊。4.再開乙個dos視窗 因為剛才那個dos視窗已經不能動了 ...

Linux下mysql 每日定時備份

1 建立shell檔案dbbak.sh執行任務 bin bash 刪除3天前資料 find ifeodata bakdata mtime 3 name exec rm rf 備份當前資料庫 並以gzip壓縮 mysqldump h ip uusername ppassword single tran...

mysql 查詢資料 程式 mysql查詢資料

1 查詢出學生表中年齡為22或者24的學生資訊 select id,name,age,addres,birthday from stu where age 22 or age 24 2 查詢出學生表中位址不為上海和深圳的所有學生資訊 select id,name,age,addres,birthda...