加载数据infile不适用于datetime周围的引号

时间:2012-08-10 06:09:21

标签: mysql

我无法加载具有所谓有效日期时间格式的文件。例如,加载文件中的行如下所示: 4,0,'2012-08-09 22:34:28','2012-08-09 22:34:28'

相同的格式适用于insert语句。加载时这不是有效的日期时间格式吗?在任何情况下我们都必须指定默认格式吗?我应该施展吗?

2 个答案:

答案 0 :(得分:0)

OP回答:

  

啊!没关系。加载文件时,日期时间不会指望它周围的引号。这一行应该是4,0,2012-08-09 22:34:28,2012-08-09 22:34:28

(从“未答复”中删除)

答案 1 :(得分:0)

LOAD DATA INFILE语句中添加

OPTIONALLY ENCLOSED BY "'"

请参阅manual了解语法:

LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name'
    [REPLACE | IGNORE]
    INTO TABLE tbl_name
    [CHARACTER SET charset_name]
    [{FIELDS | COLUMNS}
        [TERMINATED BY 'string']
        [[OPTIONALLY] ENCLOSED BY 'char']
        [ESCAPED BY 'char']
    ]
    [LINES
        [STARTING BY 'string']
        [TERMINATED BY 'string']
    ]
    [IGNORE number LINES]
    [(col_name_or_user_var,...)]
    [SET col_name = expr,...]