Convert MySQL table to CSV file
CSV is a field-separated format that can be easily imported into a spreadsheet application. Usually the separator field is a comma. However, sometimes it is easier to select a more unusual character (like “@” for example), so that the field separator is not confused with commas in the field values.
In the example below we will dump contents of table1 in database1 to /tmp/database1_table1.csv. On the command line type this:
mysql -udbuser -pdbpasswd << EOF SELECT * INTO OUTFILE '/tmp/database1_table1.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY 'n' FROM database1.table1; EOF