patternsqlMinor
import CSV into mysql table via command prompt (MySQL 5.6.25)
Viewed 0 times
promptintocsvmysqlviacommandtableimport
Problem
I'm trying to load CSV's into a mysql database with this command:
But I recieve this error:
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)):
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.
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 : File 'UsersuserNameDownloadstableName.csv' not found 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-infiledoing 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.
Solution
Since this is Windows we are dealing with, either use the double backslash
or the forward slash
It says so in the MySQL Documentation on
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.
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 INFILEThe 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.
Code Snippets
LOAD DATA LOCAL INFILE 'C:\\Users\\userName\\Downloads\\tableName.csv'
INTO TABLE tableName
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'LOAD DATA LOCAL INFILE 'C:/Users/userName/Downloads/tableName.csv'
INTO TABLE tableName
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'Context
StackExchange Database Administrators Q#106942, answer score: 2
Revisions (0)
No revisions yet.