Mysql
 sql >> Datenbank >  >> RDS >> Mysql

So exportieren Sie die Bruchzeile '\n' in einer Datei mit MySQL INTO OUTFILE

Es handelt sich um Escape-Sequenzen, und es gibt mehrere Möglichkeiten, dies zu tun. Ich habe mich dafür entschieden, das erste einfache Anführungszeichen zwischen die äußeren doppelten Anführungszeichen am Ende des ersten Weges zu setzen (mit 3 Chunks in concat). ).

Und einfache Anführungszeichen als zweite Möglichkeit (mit 2 Chunks in concat ):

SET @filename = 'C:/icl/myfile.CSV';
-- C:/icl/myfile.CSV

SET @str = CONCAT('LOAD DATA INFILE ',@filename);
-- LOAD DATA INFILE C:/icl/myfile.CSV

-- First way is below (with the result being the line after it if you ignore the `-- ` at the beginning):
SET @str = CONCAT(@str," INTO TABLE icl_process_data.filecontent LINES TERMINATED BY '","\\n'");
-- LOAD DATA INFILE C:/icl/myfile.CSV INTO TABLE icl_process_data.filecontent LINES TERMINATED BY '\n'

-- Second way is below (with the result being the line after it if you ignore the `-- ` at the beginning):
SET @str = CONCAT('LOAD DATA INFILE ',@filename);
SET @str = CONCAT(@str,' INTO TABLE icl_process_data.filecontent LINES TERMINATED BY \'\\n\'');
-- LOAD DATA INFILE C:/icl/myfile.CSV INTO TABLE icl_process_data.filecontent LINES TERMINATED BY '\n'

Von der mysql-Manpage auf String-Literale :