将.sql文件导入mysql(最终导入到excel)

时间:2017-03-15 06:38:59

标签: mysql excel windows

所以我一直在尝试将crunchbase 2013快照(一个mysql转储文件)导入excel。我一直试图通过mysql命令行或mysql worbench 6.3将它导入数据库,但到目前为止我一直没有运气。 (在Windows上工作)

我的第一步是将所有文件合并到一个转储文件中。然后我尝试导入但得到了这个错误:

  

错误:ASCII' \ 0'出现在语句中,但除非选项--binary-mode已启用且mysql以非交互模式运行,否则不允许这样做。如果ASCII' \ 0'设置--binary-mode为1是期待。查询:''。

然后我尝试将它从ANSI转换为UTF8并重新打开。我收到了与初始垃圾值相关的错误。我删除了它们然后再次尝试导入。这是新错误:

  

第2行的错误1064(42000):您的SQL语法出错;检查与您的MySQL服务器版本相对应的手册,以便在'" cb_acquisitions"附近使用正确的语法。 (     " ID" bigint(20)NOT NULL,     " acquisition_id" bigint(20)NO'在第1行

这是常规.sql文件的样子:

   Mac OS X                2   „      ¶                                      ATTR       ¶   ˜                     ˜     com.apple.quarantine q/0001;52aa111a;Transmit.app;     Mac OS X                2   „      ¶                                      ATTR       ¶   ˜                     ˜     com.apple.quarantine q/0001;52aa111a;Transmit.app;     Mac OS X                2   „      ¶                                      ATTR       ¶   ˜                     ˜     com.apple.quarantine q/0001;52aa111a;Transmit.app;     Mac OS X                2   „      ¶                                      ATTR       ¶   ˜                     ˜     com.apple.quarantine q/0001;52aa111a;Transmit.app;     Mac OS X                2   „      ¶                                      ATTR       ¶   ˜                     ˜     com.apple.quarantine q/0001;52aa111a;Transmit.app;     Mac OS X                2   „      ¶                                      ATTR       ¶   ˜                     ˜     com.apple.quarantine q/0001;52aa111a;Transmit.app;     Mac OS X                2   „      ¶                                      ATTR       ¶   ˜                     ˜     com.apple.quarantine q/0001;52aa111a;Transmit.app;     Mac OS X                2   „      ¶                                      ATTR       ¶   ˜                     ˜     com.apple.quarantine q/0001;52aa111a;Transmit.app;     Mac OS X                2   „      ¶                                      ATTR       ¶   ˜                     ˜     com.apple.quarantine q/0001;52aa111a;Transmit.app;     Mac OS X                2   „      ¶                                      ATTR       ¶   ˜                     ˜     com.apple.quarantine q/0001;52aa111a;Transmit.app;     Mac OS X                2   „      ¶                                      ATTR       ¶   ˜                     ˜     com.apple.quarantine q/0001;52aa111a;Transmit.app; -- MySQL dump 10.13  Distrib 5.5.31, for debian-linux-gnu (x86_64)
--
-- Host: 127.0.0.1    Database: analytics_2
-- ------------------------------------------------------
-- Server version   5.0.51-log
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO,POSTGRESQL' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Not dumping tablespaces as no INFORMATION_SCHEMA.FILES table on this server
--

--
-- Table structure for table "cb_acquisitions"
--

DROP TABLE IF EXISTS "cb_acquisitions";
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE "cb_acquisitions" (
  "id" bigint(20) NOT NULL,
  "acquisition_id" bigint(20) NOT NULL,
  "acquiring_object_id" varchar(64) NOT NULL,
  "acquired_object_id" varchar(64) NOT NULL,
  "term_code" varchar(16) default NULL,
  "price_amount" decimal(15,0) default NULL,
  "price_currency_code" varchar(16) default NULL,
  "acquired_at" date default NULL,
  "source_url" varchar(255) default NULL,
  "source_description" varchar(255) default NULL,
  "created_at" datetime default NULL,
  "updated_at" datetime default NULL,
  PRIMARY KEY  ("id"),
  KEY "acquiring_object_id" ("acquiring_object_id"),
  KEY "acquired_object_id" ("acquired_object_id"),
  KEY "acquisition_id" ("acquisition_id")
);
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table "cb_acquisitions"
--

LOCK TABLES "cb_acquisitions" WRITE;
/*!40000 ALTER TABLE "cb_acquisitions" DISABLE KEYS */;
INSERT INTO "cb_acquisitions" VALUES (1,1,'c:11','c:10',NULL,20000000,'USD','2007-05-30','http://venturebeat.com/2007/05/30/fox-interactive-confirms-purchase-of-photobucket-and-flektor/','Fox Interactive confirms purchase of Photobucket and Flektor','2007-05-31 22:19:54','2008-05-21 19:23:44'),(2,7,'c:59','c:72','cash',60000000,'USD','2007-07-01','http://www.techcrunch.com/2007/07/02/dea

2 个答案:

答案 0 :(得分:0)

首先将.sql转储文件导入MySQL以生成cb_acquisitions表。然后使用SELECT ... INTO OUTFILE将您的表格写入常规CSV,然后将其导入Excel:

SELECT *
FROM cb_acquisitions
INTO OUTFILE '/path/to/output.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';

关于你的转储文件,我认为表和字段名称的双引号可能是个问题。我得到了创建表并插入工作,q.v。下面的演示,但我不得不稍微使用脚本。

Rextester

答案 1 :(得分:0)

我设法使用以下命令运行mysql命令行:

body{
    font-family:"Arial", Helvetica, sans-serif;
}