How to escape commas inside CSV values when importing table to MySQL?

前端 未结 1 578
野趣味
野趣味 2021-01-04 09:49

I am trying to import a CSV file into a MySQL database table. The CSV rows look like the following:

\"00602\",\" \",\"42042\",\"15590\",\"0\",\"0\",\"0\",\"3         


        
1条回答
  •  一整个雨季
    2021-01-04 10:39

    From the MySQL Reference Manual, use the following options instead:

    LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
      FIELDS TERMINATED BY ',' ENCLOSED BY '"'
      LINES TERMINATED BY '\r\n'
    

    Update to match your usage, but the important part is to drop the OPTIONALLY from OPTIONALLY ENCLOSED BY.

    0 讨论(0)
提交回复
热议问题