1

I have an assignment to write queries in Neo4J, but the database provided is SAKILA.SQL.

How can I load it into Neo4j?

I've tried to find an answer for this, but had no luck!

Faizan Abid
  • 63
  • 1
  • 5

2 Answers2

1

Perhaps you can share your sql?

Easiest would be to insert it into a relational database, dump the table contents as CSV and import the data into Neo4j using LOAD CSV. See: http://neo4j.com/developer/guide-importing-data-and-etl/

See: http://neo4j.com/docs/stable/query-load-csv.html

For details on Cypher see: http://neo4j.com/developer/cypher/

Michael Hunger
  • 39,665
  • 3
  • 48
  • 74
  • INSERT INTO customer VALUES (4,2,'BARBARA','JONES','BARBARA.JONES@sakilacustomer.org',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(7,1,'MARIA','MILLER','MARIA.MILLER@sakilacustomer.org',11,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(8,2,'SUSAN','WILSON','SUSAN.WILSON@sakilacustomer.org',12,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(9,2,'MARGARET','MOORE','MARGARET.MOORE@sakilacustomer.org',13,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'), – Faizan Abid Nov 15 '14 at 10:19
  • as you can see, there are commas as well as parenthesis. How can I load a file like this on neo4j? It is not even a proper csv file. P.S: File extension is .sql – Faizan Abid Nov 15 '14 at 10:20
1

So you need to import (i.e. run all those insert statements) into MySQL first and then export into CSV files that Neo4j can use.

In the example Michael posted we used PostgresSQL's 'COPY' command to export CSV files. In MySQL you have a slightly different command as described over here.

You'd have something like:

SELECT * from customer
INTO OUTFILE '/tmp/customers.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

And then in Neo4j you'd have a query like this:

LOAD CSV WITH HEADERS FROM 'file:/tmp/customers.csv' AS line
MERGE (c:Customer {id: c.id})
ON CREATE SET c.name = line.name

And so on.

You can then do a similar thing to extract your other tables and use the MERGE command to create appropriate relationships between the different nodes.

If you share all the MySQL import script we can show you how to do a more complete translation.

Community
  • 1
  • 1
Mark Needham
  • 2,058
  • 15
  • 18
  • Im importing an actor.csv file from my computer (E drive) like this: LOAD CSV WITH HEADERS FROM "E/CSV/actor.csv" AS row CREATE (:Actor {actor_id: row.actor_id, first_name: row.first_name, last_name: row.last_name, last_update: row.last_update}); But it says: "Invalid URL specified (no protocol: E/CSV/actor.csv)" – Faizan Abid Nov 15 '14 at 13:35
  • 1
    Try this: LOAD CSV WITH HEADERS FROM "file:/E:/CSV/actor.csv" AS row CREATE (:Actor {actor_id: row.actor_id, first_name: row.first_name, last_name: row.last_name, last_update: row.last_update}) – Mark Needham Nov 16 '14 at 10:50