LMSouq
database Open

How can I output MySQL query results in CSV format?

MC
MCS
1 month ago
3 views
Problem Description
Is there an easy way to run a MySQL query from the Linux command line and output the results in [CSV][1] format? Here's what I'm doing now: ```lang-none mysql -u uid -ppwd -D dbname << EOQ | sed -e 's/ /,/g' | tee list.csv select id, concat("\"",name,"\"") as name from students EOQ ``` It gets messy when there are a lot of columns that need to be surrounded by quotes, or if there are quotes in the results that need to be escaped. [1]: http://en.wikipedia.org/wiki/Comma-separated_values

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base