2
votes

I am trying to export mysql table to CSV file.

In the table I have columns sorted like this:

id, name,title, content

In the content column I have some html and then I am trying to open exported file at some point lines breaks because of html quotes.

Instead of this:

id, name,title,content
1, name1, title1, <div class="class1">sometext1</div>
2, name2, title2, <div class="class2">sometext1</div>
3, name3, title3, <div class="class3">sometext1</div>
4, name3, title4, <div class="class4">sometext1</div>

I get something like this:

id, name,title,content
1, name1, title1, <div class="class1">sometext1</div>
2, name2, title2, <div class="
class2">sometext1</div>, 3, name3, title3, <div class="class3">sometext1</div>
4, name3, title4, <div class="class4">sometext1</div>
Here are my settings while exporting

Columns separated with: \t ( tab)

Columns enclosed with: "

Columns escaped with: "

Lines terminated with:AUTO

Replace NULL with: NULL

What I am doing wrong here? Also text is in UTF-8

1
i'd bet there's a tab between " and class on line id:2 - Alex Tartan
Great, but how do I get them without breaking csv ? - andy
Incidentally, what's the data type for the content column? - Isaac Bennetch
And which phpMyAdmin version are you using to perform the export? - Isaac Bennetch
@andy, have you got any solution? - Jatin Patel - JP

1 Answers

0
votes

This doesn't exactly make sense as described; using the settings you're showing -- specifically, Columns enclosed with: " and Columns escaped with: ", your data should look like this:

id, name,title,content
"1", "name1", "title1, "<div class=""class1"">sometext1</div>"
...

So clearly something went wrong with your export. I just tested with my phpMyAdmin and this works as expected, and means that on import the columns are properly parsed including the linebreaks and in-line double-quotes.

So I suggest sorting that out first.

Another solution is to change the "Lines terminated with" delimiter, probably also "Columns enclosed with" although as mentioned that isn't working in your export anyway. What you set it to will depend on your other data; you'll have to find some character that doesn't exist in your database. Remember to use that character when importing, too, and override the default selection of "auto."