导入到mysql中

时间:2009-04-29 22:19:01

标签: sql mysql database csv import

我正在尝试使用以下行将CSV文件导入MySQL 5.0:

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

我的表架构如下

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` ));

我尝试导入的数据示例,其中包含ARTICLE_NAME字段的故意剪切HTML:

"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"">

<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

我不对导入的数据负责。

此数据导出到没有网络连接的计算机上的CSV文件,因此无法直接导入数据库。我已尝试使用ESCAPED BY子句,但没有多大帮助。

我想知道如何正确导入数据,或者以可以直接导入的方式将数据导出到CSV文件。 CSV文件从Microsoft Access 2003数据库导出,使用UTF-8,分隔符用逗号和“"”括起来的字段。

1 个答案:

答案 0 :(得分:2)

你的负荷是说FIELDS TERMINATED BY';'而其他一切都暗示终结者是','而这可能是问题吗?