Skip to content

Instantly share code, notes, and snippets.

@mdp
Last active August 29, 2015 21:15
Show Gist options
  • Select an option

  • Save mdp/46127 to your computer and use it in GitHub Desktop.

Select an option

Save mdp/46127 to your computer and use it in GitHub Desktop.
#mySQL CSV Exports
## On the command line
mysql -u exampleuser -p letmein exampledb -B -e "select * from \`person\`;" | sed ’s/\t/”,”/g;s/^/”/;s/$/”/;s/\n//g’ > filename.csv
## and with a direct mySQL query
SELECT * INTO OUTFILE '/tmp/result.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM test_table WHERE 'all'='good';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment