How does one use mysqlimport with reserved-word table name?

68 views Asked by At

A third party has provided a table in CSV format that is named, "KEY.txt". When using mysqlimport to import the file, the following error is returned:

$ mysqlimport fooDB KEY.txt
mysqlimport: Error: 1064, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'KEY' at line 1, when using table: KEY

Of course, using reserved words as table and column names is a Bad Idea™. One solution would be to simply rename the file to a non-reserved word, but this is not ideal.

However, MySQL does support using reserved words, as long as the table or column name is put in backtick quotes. The following query from within the mysql client works:

mysql> LOAD DATA LOCAL INFILE 'KEY.txt" INTO TABLE `KEY`;
Records: 303  Deleted: 0  Skipped: 0  Warnings: 0

Is there a way to get mysqlimport to backtick-quote the table name?

1

There are 1 answers

0
Brad303 On

As of this writing (v8.0.31 client, v8.0.18 server) mysqlimport does indeed properly handle reserved-word table names as expected, as long as the --delete option isn't specified (as an argument, or in my.cnf).