Wednesday, January 4, 2012

Mysql Export and Import from select statement

To export into a csv file from a select statement in mysql, the command is

SELECT * INTO OUTFILE 'data.txt'
FIELDS TERMINATED BY ','
FROM table2;

To read the comma-delimited file back in, the correct statement would be:

LOAD DATA INFILE 'data.txt' INTO TABLE table2
FIELDS TERMINATED BY ',';

No comments: