MySQL命令列匯出、匯入 Select 查詢結果

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   ar   檔案   資料   2014   

<!-- 環境: Windows 2003 SP2 + MySQL5.5.28  -->

 

有的時候需要把在一張表中用 select 語句查詢出來的結果儲存到另一張結構相同的表中,可以在命令列下使用一對SQL陳述式完成該操作:

匯出查詢結果:Select語句 into outfile ‘儲存路徑+檔案名稱‘;

匯入查詢結果:load data local infile ‘儲存路徑+檔案名稱‘ into table 表明 character set utf8;

 

例如:

查詢出資料庫jc1992中表jc_archives中發布時間晚於2014年9月1日的資料並儲存在本地磁碟D的mysqltmp目錄下,儲存為1.sql,在命令列中輸入:

SELECT * from jc_archives where senddate>UNIX_TIMESTAMP(‘2014-9-1‘ ) into outfile ‘D://mysqltmp/1.sql‘;

結果

 

1.sql用EditPlus開啟

 

再把儲存查詢結果的1.sql匯入到另一資料庫data_tmp的表archives中,在命令列中輸入:

load data local infile "D://mysqltmp/1.sql" into table archives character set utf8;

結果

 

這樣就把第一張表中的查詢結果匯入了第二張表。要注意的是在匯入時,兩張表的主鍵或者唯一索引的值不能有重複,否則會跳過不執行或者警示告:

MySQL命令列匯出、匯入 Select 查詢結果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.