#Neo4j Graphic DB 图型数据库入门

该文详细介绍了如何为初学者配置Neo4j,包括安装Docker和JDK,创建Docker本地卷,从DockerHub下载Neo4j社区版,启动并设置Neo4j,以及登录数据库。接着,文章演示了如何在Neo4j中创建Person节点,建立父子、母子及夫妻关系,为图数据库操作提供了基础示例。
摘要由CSDN通过智能技术生成

Neo4jDemo

For Beginner Study Neo4j

1. Prerequisite

  • install docker

  • install JDK

1.1 create docker local volume

docker volume create neo4j_data & docker volume create neo4j_logs & docker volume ls

2. Install Neo4j

2.1 download Neo4j Community version from docker hub

docker pull neo4j:5.3.0-community

Note: recommend download specify version for later environment setup

2.2 Start up Neo4j

mkdir data & docker run -d\
    --publish=7474:7474 --publish=7687:7687 \
    --volume=neo4j_data:/data \
    --volume=neo4j_logs:/logs \
    --env NEO4J_AUTH=neo4j/neo4jtest \
    neo4j:5.3.0-community

Note: docker command params

  • -d: which sending current docker process to background

  • --publish: which mapping container port 7474, 7687 to local machine

  • --volume: mount docker volume into container

  • --env NEO4J_AUTH setting neo4j auth environment. here reset neo4j default username & password to neo4j/neo4jtest

2.3 Access Neo4j and login with neo4j/neo4jtest

http://localhost:7474

which allows you to access neo4j through your browser at http://localhost:7474.

This binds two ports (7474 and 7687) for HTTP and Bolt access to the Neo4j API. A volume is bound to /data to allow the database to be persisted outside the container.

By default, this requires you to login with neo4j/neo4j and change the password. For development purposes, disable authentication by passing --env=NEO4J_AUTH=none to docker run.

Noted: Enter username (neo4j) and password (neo4jtest) and click Connect

2.4 Success Login Neo4j

3 Create Neo4j Nodes

3.1 Create first Node

  • Node type: Person

  • Node label: name: Person1

create(n:Person{name:'Person1'}) return n

3.2 Create Person Parents Node

  • Node type: Person

  • Node label: name: Father / Mater

create(n:Person{name:'Father'}) return n
create(n:Person{name:'Mather'}) return n

3.3 Query all nodes

we can see all 3 nodes are created in Neo4j

3.4 Create relationships

Create Father and Son Relationship

MATCH(n:Person), (p:Person)
where n.name='Father' AND p.name='Person1'
create (p)-[child:SON_OF]->(n)

Create Materh and Son Relationship

MATCH(n:Person), (p:Person)
where n.name='Mather' AND p.name='Person1'
create (p)-[child:SON_OF]->(n)

Verify Result

*Create Father and Mather Relationship

MATCH(n:Person), (p:Person)
where n.name='Mather' AND p.name='Father'
create (n)-[COUPLE:wife]->(p)
MATCH(n:Person), (p:Person)
where n.name='Mather' AND p.name='Father'
create (p)-[COUPLE:Husband]->(n)

Verify Result

Until now, we have built up the simple parent and child relationship.

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值