Sunday, October 29, 2017

MySQL Import/Export

Load a table from a comma separated value file:

Table must already exist.  mysql does not create the table for me.

LOAD DATA INFILE 'importFile.csv' INTO TABLE myTable FIELDS TERMINATED BY ',';

Export a table TO a CSV:
SELECT col1, col2
FROM table1, table2
WHERE table1.key = table2.key
INTO OUTFILE '/tmp/exportFile.csv' FIELDS TERMINATED BY ',';


[Summarized from Learning MySQL]