10/23/2012

Import csv file from Select of MySQL

When you want to export csv file from MySQL, you may use phpMyAdmin as first choice. But you may use select clause to export csv file as another choice. The following is one example.

Table
name
Sam
Bush
....
Jone

mysql > select * from test_table where name LIKE "good"   INTO OUTFILE "/tmp/export.csv" fields terminated by ',';

After you execute the above code, you mat get export.csv at your tmp directory. On the contrary, you may import from csv file.


mysql > load DATA LOCAL INFILE  "/tmp/export.csv" INTO TABLE test_table  fields terminated by "," LINES TERMINATED BY "\r\n";



No comments:

Post a Comment