0 votes
1 view
in SQL by (2.5k points)

Here's what I'm doing now:

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 Answer

0 votes
by (6.5k points)

To find the output MySQL query results in CSV format.

You need to use this command only___

SELECT order_id,product_name,qty+

FROM orders 

WHERE foo = 'bar' 

INTO OUTFILE '/var/lib/mysql-files/orders.csv' 

FIELDS TERMINATED BY ','

ENCLOSED BY '"' 

LINES TERMINATED BY '\n';

We are using this command but their column name will not be exported.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...