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 :(
The default delimiter in the mysql client (from MariaDB 10.4. 6, also called mariadb) is the semicolon.
The MySQL delimiter occurs when you are using a pipe delimiter(|) with semicolon (;) and using MySQL version lower than 8.0. 12. MySQL treats the pipe (|) as one delimiter and semicolon (;) is another delimiter.
By default, mysql itself recognizes the semicolon as a statement delimiter, so you must redefine the delimiter temporarily to cause mysql to pass the entire stored program definition to the server.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With