sql查询结果保存与文件读取

将查询结果保存到文件里, 注意 如果已经存在同名文件,则不会创建。

SELECT…INTO OUTFILE

例子:

select name,ctfid,birthday,mobile,tel,email from info where ctfid like '130000%' into outfile '/tmp/fuping-of-rujia';

同时可以指定分隔符等

SELECT a,b,a+b INTO OUTFILE '/tmp/result.text'

FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'

LINES TERMINATED BY '\n'

FROM test_table;

从文件读取的语法为

LOAD DATA INFILE

同样可以指定分隔符等,例如从csv文件导入:

load data local infile '1-200W.csv' into table `info` fields terminated by ',' lines terminated by '\n';

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.