Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql delimiter question

Tags:

mysql

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 :(

like image 225
piet Avatar asked Sep 21 '10 13:09

piet


People also ask

What is the delimiter in mysql?

The default delimiter in the mysql client (from MariaDB 10.4. 6, also called mariadb) is the semicolon.

What is delimiter error?

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.

Why do we change the delimiter before we write a PL SQL block in mysql?

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.


1 Answers

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
like image 143
Doomsday Avatar answered Oct 03 '22 03:10

Doomsday