Search code examples
mysqlsqlinto-outfile

mysql: Dump table info a file while suppressing cell's multilines


I'm using MYSQL
how do I Dump table info a file while suppressing cell's multilines

i can use the folowing command to dump table to a file
select * from tableName into outfile 'c:/res.csv' FIELDS TERMINATED BY ','

but if there will be cells with multilines it will break the record into sevral lines
how can i avoid this?


Solution

  • If you add OPTIONALLY ENCLOSED BY '"' then data that consists of multiple lines will be enclosed by a "character. It wouldn't stop the records from breaking into several lines but a good csv reader should be able to read your csv file.

    If that's not an option I'm afraid the only option is using REPLACE to filter out newline characters.