Chinaunix首页 | 论坛 | 博客
  • 博客访问: 815047
  • 博文数量: 127
  • 博客积分: 3662
  • 博客等级: 中校
  • 技术积分: 1371
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-02 12:36
个人简介

Linux&MySQL&PHP&Nginx&Apache&MSSQL&Shell

文章分类

全部博文(127)

文章存档

2016年(1)

2015年(8)

2014年(14)

2013年(26)

2012年(17)

2011年(28)

2010年(33)

分类: Mysql/postgreSQL

2012-04-27 13:36:51

--使用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


阅读(29976) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~