--使用SELECT ... INTO OUTFILE 以逗號分隔字段的方式將數據導入到一個文件中:
- LOAD DATA INFILE 'C:\\log1.txt' INTO TABLE aa.log2 FIELDS TERMINATED BY ',';
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- 使用select * into outfile 導出
- SELECT * INTO OUTFILE '/tmp/fi.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM test.fi;
"2013-04-09 00:06:56","100000198108800","EXPORT_INFO","BUY_ITEM_INNER",65,10,1004,10,"11","2",100
"2013-04-09 00:06:59","1068029027","EXPORT_INFO","BUY_ITEM_INNER",16,7,304,7,"11","2",70
"2013-04-09 00:08:27","100000198108800","EXPORT_INFO","BUY_ITEM_INNER",65,2,1004,2,"11","2",20
-- 導入
- LOAD DATA INFILE '/tmp/fi.txt' INTO TABLE test.fii FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';
總結:
FIELDS TERMINATED BY
','
字段間分割符
OPTIONALLY ENCLOSED BY
'"'
將字段包圍 對數值型無效
LINES TERMINATED BY
'\n' 換行符
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
mysqldump也有一樣功能
- # mysqldump -uroot -p -T/tmp test fi --fields-enclosed-by=\" --fields-terminated-by="\t