views:

76

answers:

1

I am trying to import a CSV file into MySQL 5.0 with the following line:

LOAD DATA LOCAL INFILE 'file' INTO TABLE MYTABLE FIELDS TERMINATED BY ';' ENCLOSED BY '"' ESCAPED BY '\\'

My table schema is as follows

CREATE TABLE AUCTIONS (
  ARTICLE_NO      VARCHAR(20),
  ARTICLE_NAME    VARCHAR(100),
  SUBTITLE        VARCHAR(20),
  CURRENT_BID     DECIMAL(5,2),
  START_PRICE     DECIMAL(5,2),
  BID_COUNT       VARCHAR(20),
  QUANT_TOTAL     VARCHAR(20),
  QUANT_SOLD      VARCHAR(20),
  ACCESSSTARTS    VARCHAR(20),
  ACCESSENDS      VARCHAR(20),
  ACCESSORIGIN_END VARCHAR(20),
  USERNAME       VARCHAR(20),
  BEST_BIDDER_ID  VARCHAR(20),
  FINISHED        TINYINT,
  WATCH           TINYINT,
  BUYITNOW_PRICE  DECIMAL(5,2),
  PIC_URL         VARCHAR(120),
  PRIVATE_AUCTION TINYINT,
  AUCTION_TYPE    VARCHAR(20),
  ACCESSINSERT_DATE     VARCHAR(20),
  ACCESSUPDATE_DATE     VARCHAR(20),
  CAT_DESC        VARCHAR(20),
  CAT_PATH       VARCHAR(20),
  ARTICLE_DESC    TEXT,
  COUNTRYCODE     VARCHAR(20),
  LOCATION        VARCHAR(20),
  CONDITIONS      VARCHAR(20),
  REVISED         TINYINT,
  PAYPAL_ACCEPT   TINYINT,
  PRE_TERMINATED  TINYINT,
  SHIPPING_TO     VARCHAR(20),
  FEE_INSERTION   DECIMAL(5,2),
  FEE_FINAL       DECIMAL(5,2),
  FEE_LISTING     DECIMAL(5,2),
  PIC_XXL         TINYINT,
  PIC_DIASHOW     TINYINT,
  PIC_COUNT       VARCHAR(20),
  ITEM_SITE_ID    VARCHAR(20),
  STARTS          DATETIME,
  ENDS            DATETIME,
  ORIGIN_END      DATETIME,
  PRIMARY KEY ( `ARTICLE_NO` ));

An example of the data I am trying to import, which contains intentionally snipped HTML for the ARTICLE_NAME field:

"160330609276","Ed Hardy White Tiger Panther Schuhe Gr.40 18ER103W Neu","",£40.50,£1.00,5,1,0,24/04/2009 14:41:16,27/04/2009 14:41:16,27/04/2009 14:41:16,"brand-leader-europe",0,0,0,£0.00,"http://www.modestern.de/ebay/18ER103W/Galeriebild.jpg",0,1,27/04/2009 13:43:30,27/04/2009 13:43:46,"Damenschuhe","Kleidung & Accessoires","
<!DOCTYPE html PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN""
   ""http://www.w3.org/TR/html4/loose.dtd""&gt;

<html>
<head>
  <title>Brand-Leader-Europe - Because Fashion is our Business</title>
  <meta http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"">
</head>

<style type=""text/css"">
body {
    background-color: #E2E3E0;
}
</style>

<script language=""Javascript"">
function showArtikel() {
  if(document.getElementById)
  document.getElementById(""artikelbeschreibung"").style.display = ""block"";
  document.getElementById(""bezahlung"").style.display = ""none"";
  document.getElementById(""widerrufsrecht"").style.display = ""none"";
  document.getElementById(""ueberuns"").style.display = ""none"";
  document.getElementById(""kontakt"").style.display = ""none"";
  document.getElementById(""agb"").style.display = ""none"";
  document.getElementById(""impressum"").style.display = ""none"";
}
<!-- AfterbuyListing -->",77,"Berlin",1,0,1,0,77,£0.25,£0.00,£0.25,0,0,1,77

I am not responsible for the data being imported.

This data is exported to a CSV file on a machine with no network connection, so importing into the db directly is not an option. I have tried with the ESCAPED BY clause, which does not help much.

I would like to know how I can either import the data correctly, or export the data to a CSV file in a way that can be imported directly. The CSV file is exported from a Microsoft Access 2003 database, using UTF-8, commas for delimiters, and fields enclosed by '"'.

+2  A: 

Your LOAD is saying FIELDS TERMINATED BY ';' while everything else suggests the terminator is ',' instead, could that be the problem?

Alex Martelli
Wow...I feel foolish. Fixed, and thanks.
Thats a good spot, LINES TERMINATED BY ';' is probably what he's after
Phil Carter