MySQL的加载数据在每个字段单引号

时间:2019-02-05 14:44:14

标签: mysql

我有一个CSV,每个字段周围都有单引号,这些字段由制表符分隔。尝试使用LOAD DATA INFILE,但它使用单引号将其加载到每一列中。

以下是CSV数据的示例:

'pro0718398'    '1' '$slideblk' '2018/07/01 07:07:00'   'f0\\hich\\f0\\''9188 regulations'

这是我在MySQL中使用的代码:

LOAD DATA LOCAL INFILE 'data.txt'INTO TABLE testTable 
FIELDS TERMINATED BY '\t' ESCAPED BY ''
LINES TERMINATED BY '\n'
(@col1,@col2,@col3,@col4,@col5,@col6,@col7,@col8) set col1=@col1, col2=@col2, col3=@col3, col4=@col4, col5=@col5, col6=@col6, col7=@col7, col8=@col8;

1 个答案:

答案 0 :(得分:0)

我找到了答案,方法是添加“ ENCLOSED BY'\”

LOAD DATA INFILE 'data.txt'
INTO TABLE testTable
FIELDS TERMINATED BY '\t' ESCAPED BY '\\' ENCLOSED BY '\''
LINES TERMINATED BY '\n'
(@col1,@col2,@col3,@col4,@col5,@col6,@col7,@col8) 
set col1=@col1, col2=@col2, col3=@col3, col4=@col4, col5=@col5, col6=@col6, col7=@col7, col8=@col8;