跳至主要內容

图数据库 Neo4j

Liz大约 1 分钟LLMNeo4j

图数据库 Neo4j

1. Neo4j简介

Neo4j 是一款高性能的NoSQL图数据库,专注于存储和查询复杂关系数据。

图数据库是基于图论实现的一种NoSQL数据库,其数据存储结构和数据查询方式都是以图论为基础的。

特点

  • 数据模型:采用节点(Node)、关系(Relationship)和属性(Property)的图结构,能直观表示实体间的复杂连接
  • 查询语言:支持 Cypher 声明式查询语言,简化图遍历操作
  • 性能优势:通过免索引邻接等设计实现高效关系查询,尤其在深度遍历(如 K-Hop 查询)场景下,响应速度可比传统数据库快千倍
  • 事务支持:完全兼容 ACID 事务,保障数据一致性

2. Mac 安装

brew install neo4j

3. 启动

neo4j start

4. 重启

neo4j restart

5. 关闭

neo4j stop

6. 访问网页

http://localhost:7474/

默认账户和密码均为neo4j

可自行设置新密码

7. 安装apoc插件

1.查看版本,如版本2025.01.0

neo4j --version

2.在Github上下载对应版本的jar包

https://github.com/neo4j/apoc/releases

3.将jar包移到neo4j的plugins路径下面

Directories in use:
home:         /opt/homebrew/Cellar/neo4j/2025.01.0/libexec
config:       /opt/homebrew/Cellar/neo4j/2025.01.0/libexec/conf
logs:         /opt/homebrew/var/log/neo4j
plugins:      /opt/homebrew/Cellar/neo4j/2025.01.0/libexec/plugins
import:       /opt/homebrew/Cellar/neo4j/2025.01.0/libexec/import
data:         /opt/homebrew/var/neo4j/data
certificates: /opt/homebrew/Cellar/neo4j/2025.01.0/libexec/certificates
licenses:     /opt/homebrew/Cellar/neo4j/2025.01.0/libexec/licenses
run:          /opt/homebrew/Cellar/neo4j/2025.01.0/libexec/run

4.修改conf路径下的neo4j.conf配置文件

添加如下内容

dbms.security.procedures.unrestricted=apoc.*
dbms.security.procedures.allowlist=apoc.*

5.重启neo4j后验证

RETURN apoc.version()