Search code examples
mysqlload-data-infile

MySQL Load Data Query: Issue with Backslash ( \ )


I have I have a huge csv file with 149 column and 25K+ rows to upload this file in MySQL table I am using MySQL LOAD DATA Query
MY Query is:

LOAD DATA local INFILE '/Dir/file.csv' INTO TABLE my_table FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' IGNORE 1 LINES

My query is working fine, the problem comes when my file has any Backslash (\) characters, the column value get disturb and file cell value not inserting in correct columns. is there any fix for this issue.
Thanks


Solution

  • LOAD DATA local INFILE '/Dir/file.csv' INTO TABLE my_table FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\b' LINES TERMINATED BY '\n' IGNORE 1 LINES
    

    Use '\b' as escape character instead of '\' in your query.