neo4j docker 容器 neo4j-admin import 導入csv數據

一、創建docker容器

1、先創建兩個目錄 一個data 用來掛載數據庫文件,一個import 用來存放導入的csv文件

執行命令:
docker run -itd --name neo4j -p 7474:7474 -p 7687:7687 --env=NEO4J_AUTH=none -v import的絕對路徑:/var/lib/neo4j/import -v data的絕對路徑:/data neo4j

二、刪除data/databases/graph.db/ 下的所有文件

neo4j-admin import 只能在空庫下執行

三、新建csv文件

students.csv

studentId:ID,name,age:int,:LABEL
11,"學生一",18,Student
12,"學生二",16,Student
13,"學生三",17,Student
14,"學生四",19,Student

classes.csv

classId:ID,name,:LABEL
21,"一班",Class
22,"二班",Class
23,"三班",Class
24,"四班",Class

teacher.cav

teacherId:ID,name,:LABEL
31,"趙老收",Teacher
32,"王老師",Teacher

relations.csv

:START_ID,:END_ID,score,:TYPE
11,21,100,Study_in
12,21,100,Study_in
13,22,100,Study_in
14,23,100,Study_in
11,31,100,Teach
12,32,100,Teach
31,21,100,Work_in
32,22,100,Work_in

四、執行導入

docker exec -it neo4j bash
進入容器
執行命令 bin/neo4j-admin import
root@b688ef5e8f80:/var/lib/neo4j# bin/neo4j-admin import --nodes =import/students.csv --nodes=import/classes.csv --nodes=import/teacher.csv --relationships=import/relations.csv --database=graph.db 

輸出
Neo4j version: 3.5.12
Importing the contents of these files into /data/databases/graph.db:
Nodes:
  :Student
  /var/lib/neo4j/import/students.csv

  :Classes
  /var/lib/neo4j/import/classes.csv

  :Teacher
  /var/lib/neo4j/import/teacher.csv
Relationships:
  /var/lib/neo4j/import/relations.csv

Available resources:
  Total machine memory: 1.95 GB
  Free machine memory: 723.71 MB
  Max heap memory : 444.50 MB
  Processors: 4
  Configured max memory: 1.37 GB
  High-IO: false

WARNING: 753.50 MB memory may not be sufficient to complete this import. Suggested memory distribution is:
heap size: 1.00 GB
minimum free and available memory excluding heap size: 774.16 MBImport starting 2019-11-21 09:02:54.703+0000
  Estimated number of nodes: 21.00 
  Estimated number of node properties: 50.00 
  Estimated number of relationships: 9.00 
  Estimated number of relationship properties: 0.00 
  Estimated disk space usage: 1.47 kB
  Estimated required memory usage: 774.16 MB
。
。
。
-......... .......... .......... .......... ..........   5% ∆56ms
.......... .......... .......... .......... ..........  10% ∆0ms
.......... .......... .......... .......... ..........  15% ∆1ms
.......... .......... .......... .......... ..........  20% ∆0ms
.......... .......... .......... .......... ..........  25% ∆2ms
.......... .......... .......... .......... ..........  30% ∆0ms
.......... .......... .......... .......... ..........  35% ∆1ms
.......... .......... .......... .......... ..........  40% ∆1ms
.......... .......... .......... .......... ..........  45% ∆0ms
.......... .......... .......... .......... ..........  50% ∆1ms
.......... .......... .......... .......... ..........  55% ∆0ms
.......... .......... .......... .......... ..........  60% ∆1ms
.......... .......... .......... .......... ..........  65% ∆0ms
.......... .......... .......... .......... ..........  70% ∆1ms
.......... .......... .......... .......... ..........  75% ∆0ms
.......... .......... .......... .......... ..........  80% ∆1ms
.......... .......... .......... .......... ..........  85% ∆1ms
.......... .......... .......... .......... ..........  90% ∆1ms
.......... .......... .......... .......... ..........  95% ∆1ms
.......... .......... .......... .......... .......... 100% ∆0ms


IMPORT DONE in 1s 337ms. 
Imported:
  10 nodes
  8 relationships
  24 properties
Peak memory usage: 781.79 MB

退出容器
root@b688ef5e8f80:/var/lib/neo4j# exit
exit
重啓容器
docker restart neo4j


五、登錄http://ip:7474/browser/

查看導入的數據

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章