Skip to content

Instantly share code, notes, and snippets.

@postnati
Created May 27, 2011 15:05
Show Gist options
  • Save postnati/995432 to your computer and use it in GitHub Desktop.
Save postnati/995432 to your computer and use it in GitHub Desktop.
Create MySQL CSV using SELECT's INTO OUTFILE
mysql --user=root --password='' -e "SELECT GROUP_CONCAT(COLUMN_NAME SEPARATOR '\t') FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema='phineas_and_ferb' and table_name='characters' INTO OUTFILE '~/tmp/output.txt' FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '' ESCAPED BY '' LINES TERMINATED BY '\n';"
mysql --user=root --password='' phineas_and_ferb -e "SELECT * FROM characters INTO OUTFILE '~/tmp/data.txt' FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n';"
cat ~/tmp/data.txt >> ~/tmp/output.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment