我要将一些数据从CSV文件导入到MySQL数据库中。直到我在Description
字段中使用单引号的行出现之前,这一直很好。
CSV中有问题的行是这样的:
"2019","3982","2018-12-16","black, height - 16.0 ', matte, waterproof, ellipsoid","42","PXC Mfg Inc","emarkham@______.com"
SQL导入是
LOAD DATA INFILE :file
INTO TABLE $table_name
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(Year,Price,StockDate,Description,Quantity,Supplier,Contact)
鉴于所有列都用双引号引起来,我将期望作为结果
Year | Price | StockDate | Description | Quantity | Supplier | Contact
------+-------+------------+------------------------------------------------------+----------+-------------+---------------------
2019 | 3982 | 2018-12-16 | black, height - 16.0 ', matte, waterproof, ellipsoid | 42 | PXC Mfg Inc | emarkham@______.com
但是我实际上得到的是
Year | Price | StockDate | Description | Quantity | Supplier | Contact
------+-------+------------+----------------------+-----------+-----------+----------
2019 | 3982 | 2018-12-16 | black, height - 16.0 | 0 | waterproof| ellipsoid
如您所见,单引号(指示16英寸)已被解释为该值的结尾。当然,这不是理想的结果。
有人知道如何纠正这个问题吗?