Created
December 2, 2020 10:44
-
-
Save mirkoperillo/972d02362223da907e8d0b59e6c2259c to your computer and use it in GitHub Desktop.
Export csv from mysql by query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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