将查询结果保存到文件里, 注意 如果已经存在同名文件,则不会创建。
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';
Leave a Reply