Getting -lines-terminated-by to work in mysqldump

Below is the code that I use to back up my tab delimited database.

mysqldump --user=**** --fields-enclosed-by=\" --lines-terminated-by="\n" --password=**** --host=localhost --tab=/path/to/folder **** 

What I cannot get is the following:

 --lines-terminated-by="\n" 

At the moment, if I have a TEXT column in my MySQL database, it is output as follows:

 "1" "A test post" "This is an example of text on multiple lines. \ As you can see this is how it places it in the txt file. \ Blah blah blah" "2" "Another post" "More text....." 

This is what I'm trying to achieve.

 "1" "A test post" "This is an example of text on multiple lines.\nAs you can see this is how it places it in the txt file.\nBlah blah blah" "2" "Another post" "More text....." 

According to docs, --lines-terminated-by=... supported on output using --tab . But I can’t make it work.

+4
source share
1 answer

The result obtained corresponds to the documentation for SELECT ... INTO OUTFILE . Line breaks have a default escape character prefix of \ . The --lines-terminated-by option refers to which character is used as the separator for the records, and not how the lines break up inside the field.

There is no way to make the output as you want directly from mysqldump , but you can post-process the files to get the desired results. For example, you can filter files with:

 perl -pe 's/\\\n/\\n/' 
+3
source

Source: https://habr.com/ru/post/1499577/


All Articles