neo4j初尝试

neo4j 下载并安装

这里以ubuntu 下载为例

打开neo4j官网,如下图所示,找到下载中心

选择

每个人可以根据自己的系统进行下载。然后解压tar -xf neo4j-community-2025.04.0-unix.tar.gz,如果不出意外的话,这里就可以直接输入命令启动了,

复制代码
./neo4j console

但是有的时候会出现类似java版本的问题,比如

这时候,按照要求升级java的版本

复制代码
apt update
apt install openjdk-21-jre

之后再去输入启动命令,neo4j就能正常启动了。

如果你想改一些配置如监听地址或者端口号,在这里该就可以

之后再输入./neo4j restart,打开页面就可以

如果是在服务器上,根据你修改的地址进行连接

用Python 连接neo4j数据库

python 复制代码
from py2neo import Graph,Node,Relationship
uri = "bolt://140.210.92.250:16310"##对应的是原始端口7687
client=Graph(uri,user="neo4j",password="your password")
cmd='match (n) detach delete n'
client.run(cmd)
try:
    # 创建节点
    alice = Node("Person", name="Alice", age=30, city="Beijing")
    bob = Node("Person", name="Bob", age=25, city="Shanghai")
    carol = Node("Person", name="Carol", age=28, city="Guangzhou")
    company = Node("Company", name="TechCorp", industry="IT")
    
    # 创建关系
    alice_bob_friends = Relationship(alice, "FRIENDS_WITH", bob, since=2023)
    bob_carol_friends = Relationship(bob, "FRIENDS_WITH", carol, since=2024)
    alice_works = Relationship(alice, "WORKS_FOR", company, role="Engineer")
    carol_works = Relationship(carol, "WORKS_FOR", company, role="Designer")
    
    # 保存到数据库
    client.create(alice | bob | carol | company | alice_bob_friends | bob_carol_friends | alice_works | carol_works)
    print("节点和关系创建成功")
except Exception as e:
    print(f"创建节点或关系失败: {e}")
相关推荐
serve the people15 小时前
tensorflow 零基础吃透:RaggedTensor 的重载运算符
人工智能·tensorflow·neo4j
大、男人15 小时前
python之知识图谱(Neo4j)
人工智能·知识图谱·neo4j
serve the people2 天前
tensorflow 零基础吃透:tf.data 中 RaggedTensor 的核心用法(数据集流水线)
人工智能·tensorflow·neo4j
serve the people3 天前
tensorflow 零基础吃透:不规则张量(RaggedTensor)vs 稀疏张量(SparseTensor)
人工智能·tensorflow·neo4j
shayudiandian3 天前
深度学习可视化:用TensorBoard分析模型训练过程
人工智能·深度学习·neo4j
serve the people3 天前
零基础吃透 RaggedTensor 文本特征提取示例(通俗版)
neo4j
serve the people4 天前
tensorflow不规则张量(RaggedTensor)的存储约束
人工智能·tensorflow·neo4j
serve the people4 天前
TensorFlow 中不规则张量(RaggedTensor)
人工智能·tensorflow·neo4j
serve the people4 天前
TensorFlow 不规则张量(RaggedTensor)的两种核心构造方式
人工智能·tensorflow·neo4j
serve the people4 天前
TensorFlow 高级自动微分
人工智能·tensorflow·neo4j