MySQL批處理SQL語句,mysql批處理sql

來源:互聯網
上載者:User

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語句的參數,也就是讀取檔案內的語句運行,但我用的不多給忘了。-?裡有。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.