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 c
SELECT INTO OUTFILE
requires ** FILE ** permissions for mysql user https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html (permission to write on mysql host filesystem). It's vulnerability issue and therefore database's ** ALL PRIVILEGES ** not includes FILE permissions.
In most cases better use pipeline replacement from tabulation symbols \t
to any character you want ,
:
mysql -h -p dbname -e 'SELECT * FROM table_name;' | sed 's/\t/,/g' > out.csv
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' "
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
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