MySQL批處理SQL語句

來源:互聯網
上載者:User

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

--------------------------------------分割線 --------------------------------------

Ubuntu 14.04下安裝MySQL

《MySQL權威指南(原書第2版)》清晰中文掃描版 PDF

Ubuntu 14.04 LTS 安裝 LNMP Nginx\PHP5 (PHP-FPM)\MySQL

Ubuntu 14.04下搭建MySQL主從伺服器

Ubuntu 12.04 LTS 構建高可用分布式 MySQL 叢集

Ubuntu 12.04下原始碼安裝MySQL5.6以及Python-MySQLdb

--------------------------------------分割線 --------------------------------------

本文永久更新連結地址:

相關文章

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.