Austin Corley
Austin Corley

Reputation: 1

MySQL can't find my file

I'm trying to import data into a table from a .csv file, but mysql is having a hard time finding it. When I just have it in my C drive, not in a folder, it finds it fine. When I place the file I want in a folder, then put the file path in my query, it doesn't work.

The query I'm using is:

load data local infile '/C:\file_path' into table table_name fields terminated by ',' enclosed by '"' lines terminated by '\n' ignore 2 lines;

I have also tried removing 'local' to no avail

Thanks!

Upvotes: 0

Views: 2376

Answers (1)

eggyal
eggyal

Reputation: 125865

By default (i.e. unless the NO_BACKSLASH_ESCAPES SQL mode is enabled), you have to escape backslash characters in string literals.

As documented under LOAD DATA INFILE Syntax:

Windows path names are specified using forward slashes rather than backslashes. If you do use backslashes, you must double them.

Therefore, use either:

LOAD DATA [LOCAL] INFILE 'C:\\file_path' ...

Or:

LOAD DATA [LOCAL] INFILE 'C:/file_path' ...

Upvotes: 3

Related Questions