Home >Database >Mysql Tutorial >How Can I Properly Escape Special Characters When Exporting MySQL Data to a CSV Using INTO OUTFILE?
MySQL Export into Outfile: Handling CSV Escaping Characters
MySQL's INTO OUTFILE command enables efficient data exports to CSV files. However, challenges arise when encountering newlines and other special characters in exported data.
In the provided scenario, the user faces difficulties in eliminating newlines from the description field during export. Here's a solution to address this issue:
SELECT id, client, project, task, description, time, date INTO OUTFILE '/path/to/file.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM ts
The key modifications include:
Additionally, consider preceding the export statement with:
SET NAMES utf8;
This ensures proper character encoding, which may help resolve any encoding-related issues.
The above is the detailed content of How Can I Properly Escape Special Characters When Exporting MySQL Data to a CSV Using INTO OUTFILE?. For more information, please follow other related articles on the PHP Chinese website!