Jump to content

Data Import


smti

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.