tags:

views:

30

answers:

4

How do i do this:

mysql -u myuser -p mydb -e "select f1,f2 from  mytable" > /tmp/mydata.txt

But I want to separate the fields with a comma.

mysql --delimiter=, -u myuser -p mydb -e "select f1,f2 from  mytable" > /tmp/mydata.txt

Does not work :(

A: 

Put the comma between quotes:

mysql --delimiter="," -u myuser -p mydb -e "select f1,f2 from mytable" > /tmp/mydata.txt
eumiro
No then it says unknown coloum f1 :S ??
piet
A: 

I don't really understand what is the question? Can you explain what you want ?

If your wish is to add delimiter to your output, you have to use CONCAT_WS :

mysql -u myuser -p mydb -e "select CONCAT_WS(',',f1,f2) from mytable" > /tmp/mydata.txt
Doomsday
A: 

You might also try the SELECT INTO OUTFILE command to produce your CSV file. Info here: http://dev.mysql.com/doc/refman/5.1/en/select.html

Jim P
A: 

you can use INTO OUTFILE like this :

mysql  -u myuser -p  mydatabase -e 
    "select field1 , field2 FROM mytable INTO OUTFILE 
'/tmp/myfilename.csv' FIELDS TERMINATED BY ','
 ENCLOSED BY '\"' LINES TERMINATED BY '\n' "
Haim Evgi