Skip to main content

Import csv file to MySQL in Windows

LOAD DATA INFILE "C:/Users/USER/Desktop/test.csv"
INTO TABLE test
COLUMNS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;

Change the file name accordingly.  

There may be some issues.

1. SQL Error (1290): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement



You need to add LOCAL modifier LOAD DATA statement. Otherwise the following error occurred. So it looks as follows.


LOAD DATA LOCAL INFILE "C:/Users/USER/Desktop/test.csv"
INTO TABLE test
COLUMNS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;

2. Even if we add LOCAL modifier, there will be another issue as follows.

SQL Error (3948): Loading local data is disabled; this must be enabled on both the client and server sides.
 


3. So you need to enable following

SET @@GLOBAL.local_infile = 1;
But there may be security issues. You may check more information here 
After that you may upload the csv file to Mysql server properly.
Enjoy.....



Comments