mysql into outfile 總結

來源:互聯網
上載者:User

標籤:mysql   outfile   匯出與匯入   

備份文法:

select * from  表名 where 條件  into outfile ‘/tmp/表名.txt‘;

    #注意儲存位置/tmp的許可權;

    #注意備份檔案的格式;

恢複文法:

 load data infile ‘表名.txt‘ into  table 表名 ;

#注意恢複時備份檔案的位置要存放在mysql 資料庫 data 庫目錄下;


範例:根據時間欄位檢索資料:

  備份outfile:

select * from PageView where ActionTime  >=‘2015-01-01 00:00‘ and ActionTime  <=‘2015-01-01 23:59‘   into outfile ‘/tmp/PageView7.txt‘;

#注意時間的欄位;  desc 查看時間欄位;

  恢複load data infile:

load data infile ‘PageView7.txt‘ into  table PageView ;


使用SELECT * INTO OUTFILE 備份:

SELECT * INTO OUTFILE ‘/tmp/xx.txt‘ FIELDS TERMINATED BY ‘,‘ OPTIONALLY ENCLOSED BY ‘"‘ LINES TERMINATED BY ‘\n‘ FROM 表名;

    

    FIELDS TERMINATED BY ‘,‘ 欄位間分割符
    OPTIONALLY ENCLOSED BY ‘"‘ 將欄位包圍 對數值型無效
    LINES TERMINATED BY ‘\n‘ 分行符號


使用LOAD DATA INFILE恢複:

LOAD DATA INFILE ‘/tmp/xx.txt‘ INTO TABLE test.fii FIELDS TERMINATED BY ‘,‘ OPTIONALLY ENCLOSED BY ‘"‘ LINES TERMINATED BY ‘\n‘;



參考連結:
http://blog.chinaunix.net/uid-24373487-id-3191050.html
http://www.cnblogs.com/stublue/archive/2012/07/02/2573860.html

mysqldump 備份參考連結:

http://linuxboys.blog.51cto.com/9150052/1579346

本文出自 “思想大於技術” 部落格,謝絕轉載!

mysql into outfile 總結

聯繫我們

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