本文連結:http://blog.csdn.net/kongxx/article/details/7051439
MySQL自己提供了匯入匯出資料庫的工具,但有時我們需要僅僅匯入匯出單個表的資料,比如匯入匯出CSV檔案,此時可以使用MySQL自動的命令來做匯入匯出工作。
匯出文法如下:
SELECT * FROM [TABLE]<br />INTO OUTFILE '[FILE]';<br />或者<br />SELECT * FROM [TABLE]<br />INTO OUTFILE '[FILE]'<br />FIELDS TERMINATED BY ','<br />OPTIONALLY ENCLOSED BY '"'<br />LINES TERMINATED BY '\n';下邊是一個具體的匯出的例子:
SELECT * FROM mytable<br />INTO OUTFILE '/tmp/mytable.csv'<br />FIELDS TERMINATED BY ','<br />OPTIONALLY ENCLOSED BY '"'<br />LINES TERMINATED BY '\n';
匯入文法如下:
LOAD DATA INFILE '[FILE]'<br />INTO TABLE [TABLE];<br />或者<br />LOAD DATA INFILE '[FILE]'<br />INTO TABLE [TABLE]<br />FIELDS TERMINATED BY ','<br />OPTIONALLY ENCLOSED BY '"'<br />LINES TERMINATED BY '\n';下邊是一個具體的匯入的例子:
LOAD DATA INFILE '/tmp/mytable.csv'<br />INTO TABLE mytable<br />FIELDS TERMINATED BY ','<br />OPTIONALLY ENCLOSED BY '"'<br />LINES TERMINATED BY '\n';