1 安装 Docker
Windows 安装 Docker 时,需要先开启 Hyper-V
功能,启用脚本如下,新建一个文本文档,把下面的命令复制进去,把拓展名从 txt
改为 bat
,右键以管理员身份执行
pushd "%~dp0" dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i" del hyper-v.txt Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL
等待执行完成,执行成功后需要重启电脑,然后安装 Docker Desktop
Docker: Accelerated Container Application Development
选择合适的版本下载安装即可
2 安装 Neo4jDesktop
直接从官网下载安装即可
Neo4j Desktop Download | Free Graph Database Download
3 运行 Neo4j 镜像
需要先创建好挂载目录
D:\Neo4j\data
D:\Neo4j\logs
D:\Neo4j\confi
D:\Neo4j\import
D:\Neo4j\plugins
然后在 powershell 中执行如下命令,默认用户名 neo4j
和密码 abc123456
docker run ` --name neo4j ` --restart always ` --publish=7474:7474 --publish=7687:7687 ` --env NEO4J_AUTH=neo4j/abc123456 ` --volume=D:\Neo4j\data:/data ` --volume=D:\Neo4j\logs:/logs ` --volume=D:\Neo4j\conf:/var/lib/neo4j/conf ` --volume=D:\Neo4j\import:/var/lib/neo4j/import ` --volume=D:\Neo4j\plugins:/var/lib/neo4j/plugins ` --env NEO4J_server_default__listen__address=0.0.0.0 ` --env NEO4J_PLUGINS='[\"apoc\", \"apoc-extended\", \"n10s\", \"graph-data-science\"]' ` --env NEO4J_dbms_security_procedures_unrestricted=',jwt.security.*,gds.*,apoc.*' ` neo4j:5.25.1
执行成功后结果效果所示
4 使用 Neo4jDesktop 连接 neo4j 容器
5 导入数据
将要导入的 CSV 文件复制到 D:\Neo4j\import
目录下
然后进入容器内
输入 cypher-shell
回车,然后输入用户名和密码
复制粘贴执行以下命令
LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/baojing.csv" AS line MERGE (:Errorid { title: line.title }); CREATE CONSTRAINT FOR (c:Errorid) REQUIRE c.title IS UNIQUE;LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/caozuo.csv" AS line MERGE (:Caozuo { title: line.title }); CREATE CONSTRAINT FOR (c:Caozuo) REQUIRE c.title IS UNIQUE;LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/xianxiang.csv" AS line MERGE (:Xianxiang { title: line.title }); CREATE CONSTRAINT FOR (c:Xianxiang) REQUIRE c.title IS UNIQUE;LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/zhuyu.csv" AS line MERGE (:GuzhangBuwei { title: line.title }); CREATE CONSTRAINT FOR (c:GuzhangBuwei) REQUIRE c.title IS UNIQUE;LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/yuanyin2.csv" AS line MERGE (:Yuanyin { title: line.title }); CREATE CONSTRAINT FOR (c:Yuanyin) REQUIRE c.title IS UNIQUE; LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/caozuoxianxaing.csv" AS line MATCH (entity1 {title:line.title1}),(entity2 {title:line.title2}) CREATE (entity1)-[:CX { type: line.relation }]->(entity2); LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/xianxiangyuanyin.csv" AS line MATCH (entity1 {title:line.title1}),(entity2 {title:line.title2}) CREATE (entity1)-[:XY { type: line.relation }]->(entity2); LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/xianxiangxianxiang.csv" AS line MATCH (entity1 {title:line.title1}),(entity2 {title:line.title2}) CREATE (entity1)-[:XX { type: line.relation }]->(entity2); LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/xianxaingbuwei.csv" AS line MATCH (entity1 {title:line.title1}),(entity2 {title:line.title2}) CREATE (entity1)-[:XB { type: line.relation }]->(entity2); LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/xianxaingbaojing.csv" AS line MATCH (entity1 {title:line.title1}),(entity2 {title:line.title2}) CREATE (entity1)-[:XJ { type: line.relation }]->(entity2);
在 GDS 中查看导入的数据