Q:

Using MySQL OUTFILE with non-simple data

I've been using the following command to expert mysql data to a csv file. 
SELECT * INTO OUTFILE 'output.csv' FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' FROM table1;

It works for simple tables with simple data.   However, if the table contains html tags, double quotes, single quotes, ascii characters etc, it does not work propertly, i.e. it will put tabs and new lines in incorrect places, breaking up data where it shouldn't.   How can the sql script above be improved to export data with html? 

A:

I have tried SELECT...INTO OUTFILE statement, and then LOAD DATA INFILE statement, everything is OK, the HTML text was exported/imported without any mistakes (on MySQL 5.5). 
Try to add ENCLOSED BY option, it should help you, e.g. -
SELECT *
  INTO OUTFILE 'output.csv'
    FIELDS TERMINATED BY '\t' ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
FROM
  table1;

LOAD DATA INFILE 'output.csv'
  INTO TABLE table1
  FIELDS TERMINATED BY '\t' ENCLOSED BY '"'
  LINES TERMINATED BY '\n';

