MySQL INTO OUTFILE導出導入數據|mysqldump

--使用SELECT ... INTO OUTFILE 以逗號分隔字段的方式將數據導入到一個文件中:
  1. SELECT * INTO OUTFILE 'C:\\log1.txt' FIELDS TERMINATED BY ',' FROM log.log1

--將剛剛導出的文件log1.txt導入到表log1相同結構的LOG2中
  1. LOAD DATA INFILE 'C:\\log1.txt' INTO TABLE aa.log2 FIELDS TERMINATED BY ',';
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- 使用select * into outfile 導出

  1. 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

-- 導入

  1. 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也有一樣功能
  1. # mysqldump -uroot -p -T/tmp test fi --fields-enclosed-by=\" --fields-terminated-by="\t
相關文章
相關標籤/搜索