Search code examples
mysqlsqlload-data-infilemysql-8.0

How to set the IGNORE flag in mysqlsh importTable util?


The following triggers a LOAD DATA INFILE statement in mysql8:

util.importTable("sample.csv", {schema: "myschema", table: "mytable", dialect: "csv-unix", fieldsTerminatedBy: ";", showProgress: true})

Question: how can I add the IGNORE INTO flag?


Solution

  • util.importTable is using LOAD DATA LOCAL INFILE and ignores duplicate-keys by default[1]. If you want replace duplicate-keys set replaceDuplicates option to true.

    [1] MySQL Reference Manual for LOAD DATA Syntax

    Duplicate-Key Handling

    (…) With LOCAL, the default behavior is the same as if IGNORE is specified; this is because the server has no way to stop transmission of the file in the middle of the operation.