MySQL批處理SQL語句,mysql批處理sql
MySQL 支援批處理的模式執行一批SQL語句,下面的例子就是實驗MySQL如何在windows下批處理執行SQL語句。
create table test(id int,name varchar(20));
insert into test values(1,'watson');
batchfile.txt裡包含下面的一些SQL 陳述式,此檔案放在windows系統的c:/batchmysql/batchfile.txt
insert into test select * from test;
insert into test select * from test;
insert into test select * from test;
insert into test select * from test;
insert into test select * from test;
insert into test select * from test;
insert into test select * from test;
insert into test select * from test;
insert into test select * from test;
insert into test select * from test;
insert into test select * from test;
insert into test select * from test;
insert into test select * from test;
insert into test select * from test;
insert into test select * from test;
在cddl資料庫裡進行批執行上面的語句如下:
mysql -uroot -p -D cddl < c:/batchmysql/batchfile.txt
下面是把批處理裡含有查詢的資訊,輸出儲存到一個檔案裡:
此時的batchfile2.txt裡含有query的資訊(下面的3條SQL語句),下面的mysql0716.out就記錄了select * from test limit 200;查詢語句的結果集。
select * from test limit 200;
insert into test select * from test;
insert into test select * from test;
You can catch the output in a file for further processing:
mysql -uroot -p -D cddl < c:/batchmysql/batchfile2.txt >c:/batchmysql/mysql0716.out
批處理*bat 執行mysql語句怎寫
@echo off
if not exist d:\rank.sql more +5 %0>d:\rank.sql
echo >nul
mysql -h localhost -u root -p 123456 < d:\rank.sql
goto :eof
truncate table a_rank;
insert into a_rank(usersn,totalpoint,point) ;
select usersn,0,Ji from ccc order by Ji desc limit 99;
update a_rank set usernick=(select usernick from b.userinfo where usersn=a_rank.usersn);
truncate table a_rank;
WIN2000+APMSERV環境下,怎用批次檔定時運行SQL語句?(滿意繼續增值)
這個批處理可以利用mysql本身內建的mysql.exe這個程式。
@echo off
mysql -u root -p123456 -D"test" -e"show databases;"
pause
sql作業就是資料庫軟體本身內建的一種類似於任務計劃的東西。
=.=! -e"這裡面就可以寫你想要啟動並執行sql語句"
比如-e"select `name` from `xxx` where `id`=1;"
我給你解釋下幾個參數
-u 使用者名稱
-p密碼(-p和密碼之間不要有空格,注意!)
-D"test" 串連到的資料庫,也可以沒有,但sql語句中要包括處理的資料庫名
-e"要啟動並執行sql語句"
你可以輸入mysql -?查看mysql的參數,我記得有一個運行文本中sql語句的參數,也就是讀取檔案內的語句運行,但我用的不多給忘了。-?裡有。