21May/10Off
How to export from mysql into csv file
If you need to export from mysql into csv file, what you have to do is the following:
SELECT * INTO OUTFILE '/tmp/myfile.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM my_table;
to import the results from csv into mysql instead the process is the following:
LOAD DATA LOCAL INFILE '/tmp/myfile.csv'
INTO TABLE my_table
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n';
note: you need to specify all the fields in the table. if in your table there is an AUTO_INCREMENT field just set that column to 0 (zero).