smti Posted May 7, 2014 Share Posted May 7, 2014 Hello, I wrote a bash script to import some data from a CSV file. The code is as follows: Load Data local infile '/home/<USERNAME>/tstProducts.csv' into table tstProducts fields terminated by ',' enclosed by '"' lines terminated by '\n' (Name, Type, Brand, Description, ABV, TimesAvailable, Image, Website) Ignore 1 Lines; When I run the bash script I get the following error: syntax error near unexpected token `(' Any thoughts on why this may be occurring? I checked my code against a sample and everything looks correct. Any help or insight you can provide would be greatly appreciated! -smti Link to comment https://forums.phpfreaks.com/topic/288317-data-import/ Share on other sites More sharing options...
Barand Posted May 7, 2014 Share Posted May 7, 2014 The IGNORE should come before the column list MYSQL Manual said: LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name'[REPLACE | IGNORE]INTO TABLE tbl_name[PARTITION (partition_name,...)][CHARACTER SET charset_name][{FIELDS | COLUMNS}[TERMINATED BY 'string'][[OPTIONALLY] ENCLOSED BY 'char'][ESCAPED BY 'char']][LINES[sTARTING BY 'string'][TERMINATED BY 'string']][iGNORE number {LINES | ROWS}][(col_name_or_user_var,...)][sET col_name = expr,...] Link to comment https://forums.phpfreaks.com/topic/288317-data-import/#findComment-1478602 Share on other sites More sharing options...
smti Posted May 7, 2014 Author Share Posted May 7, 2014 I also tried this with the same result: LOAD DATA LOCAL INFILE '/home/jalewellyn/tstProducts.csv' INTO TABLE tstProducts FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (Name, Type, Brand, Description, ABV, TimesAvailable, Image, Website); Link to comment https://forums.phpfreaks.com/topic/288317-data-import/#findComment-1478609 Share on other sites More sharing options...
jazzman1 Posted May 8, 2014 Share Posted May 8, 2014 As for getting a bash error, you need to escape the braces otherwise everything between them it will be treated by the parser as a group of commands. Try, LOAD DATA LOCAL INFILE '/home/jalewellyn/tstProducts.csv' INTO TABLE tstProducts FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES \(Name, Type, Brand, Description, ABV, TimesAvailable, Image, Website\) Link to comment https://forums.phpfreaks.com/topic/288317-data-import/#findComment-1478660 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.