79671398

Date: 2025-06-18 23:38:14
Score: 3.5
Natty:
Report link
As a workaround, I can I run mysql from the command line and redirect the output, like:

    mysql -h host1 -D db1 -u user1 -p password1 -e "SELECT * FROM table" > test123.csv

This appears to output with the equivalent of:

    FIELDS TERMINATED BY '\t'

    LINES TERMINATED BY '\n'

The problem is my users need the CSV files in Comma Separated format.

I experimented with SED to see if I could convert any CSV file from TAB separated fields to COMMA separated fields.

This command line would seem to do it:

    sed -i -e 's/\t/","/g' -e 's/^/"/' -e 's/$/"/' test123.csv

First command replaces \t (tab) with "," (quote, comma, quote)
Second command inserts " (quote) at the beginning of each line
Third command inserts " (quote) at the end of each line

Given the restrictions I have, any thoughts as to whether this is the best approach to output MySQL data into a Comma Separated CSV?
Reasons:
  • Blacklisted phrase (1.5): any thoughts
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: PhoenixTech