MySQL INTO OUTFILE/INFILE导出导入数据

--使用SELECT ... INTO OUTFILE 以逗号分隔字段的方式将数据导入到一个文件中:

SELECT * INTO OUTFILE 'D:\\log1.txt' FIELDS TERMINATED BY ',' FROM log.log1

--将刚刚导出的文件log1.txt导入到表log1相同结构的log2中:

LOAD DATA INFILE 'D:\\log1.txt' INTO TABLE aa.log2 FIELDS TERMINATED BY ','

-- 使用select * into outfile 导出:

SELECT * INTO OUTFILE 'd:\\test.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM test.table

-- 导入

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' 换行符

 

posted @ 2014-07-08 09:51  一个坟头  阅读(18973)  评论(0编辑  收藏  举报