MySQL 5.6 – How to Import CSV into Table via Command Prompt

command linecsvMySQLmysql-5.6windows

I'm trying to load CSV's into a mysql database with this command:

LOAD DATA LOCAL INFILE '\Users\userName\Downloads\tableName.csv' 
INTO TABLE tableName 
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n'

But I recieve this error:

ERROR 2 <HY000>: File 'UsersuserNameDownloadstableName.csv' not found <Errocode: 2 - No such file or directory>

I log onto mysql with the command (as described here MySQL import csv file ERROR 13 (HY000): Can't get stat of /path/file.csv (Errcode: 2)):

mysql -u root -p --local-infile

doing what was described in the link above I was able to import the CSV's on a different MySQL Server (On a seperate machine running Ubuntu). However the same process doesn't seem to be working for a differente MySQL Server instance on a Windows machine using Command Prompt.

Best Answer

Since this is Windows we are dealing with, either use the double backslash

LOAD DATA LOCAL INFILE 'C:\\Users\\userName\\Downloads\\tableName.csv' 
INTO TABLE tableName 
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n'

or the forward slash

LOAD DATA LOCAL INFILE 'C:/Users/userName/Downloads/tableName.csv' 
INTO TABLE tableName 
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n'

It says so in the MySQL Documentation on LOAD DATA INFILE

The file name must be given as a literal string. On Windows, specify backslashes in path names as forward slashes or doubled backslashes. The character_set_filesystem system variable controls the interpretation of the file name.