Skip to content

Instantly share code, notes, and snippets.

@mirkoperillo
Created December 2, 2020 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirkoperillo/972d02362223da907e8d0b59e6c2259c to your computer and use it in GitHub Desktop.
Save mirkoperillo/972d02362223da907e8d0b59e6c2259c to your computer and use it in GitHub Desktop.
Export csv from mysql by query
mysql -u USER -p -B DB < QUERY.sql | sed 's/"/\\"/g' | sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\"NULL\"/NULL/g;s/\n//g" >RESULT.csv
@mirkoperillo
Copy link
Author

This script is an improvement of the original found in a stackoverflow answer
here the original source: https://stackoverflow.com/a/5395421/8511674

The original answer is licensed under CC BY-SA 3.0
This improved script is under the same license

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment