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

转载于:https://my.oschina.net/u/919580/blog/142102

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值