MySQL INTO OUTFILE导出导入数据|mysqldump
2016年11月29日 16:07:27
阅读数:322
--使用SELECT ... INTO OUTFILE 以逗号分隔字段的方式将数据导入到一个文件中:
--将刚刚导出的文件log1.txt导入到表log1相同结构的LOG2中
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