Memgraph 的安装教程
目录
- Memgraph 安装步骤
- 1. 使用 Docker 安装 Memgraph
- 2. 使用 Memgraph Lab
- 3. 使用 Python 客户端连接 Memgraph
Memgraph 安装步骤
1. 使用 Docker 安装 Memgraph
Memgraph 可以通过 Docker 快速安装和运行。以下是使用 Docker 安装 Memgraph 的步骤:
-
安装 Docker:
- 如果您还没有安装 Docker,请访问 Docker 官方网站 下载并安装 Docker。
-
拉取 Memgraph 镜像:
- 打开终端或命令提示符,运行以下命令以拉取 Memgraph 的 Docker 镜像:
docker pull memgraph/memgraph-mage:latest
- 打开终端或命令提示符,运行以下命令以拉取 Memgraph 的 Docker 镜像:
-
运行 Memgraph 容器:
- 使用以下命令启动 Memgraph 容器:
docker run -p 7687:7687 -p 7444:7444 --name memgraph memgraph/memgraph-mage
- 这将启动 Memgraph 并将其 Bolt 协议端口映射到本地主机的 7687 端口。
- 使用以下命令启动 Memgraph 容器:
2. 使用 Memgraph Lab
Memgraph Lab 是一个图形化用户界面,可以帮助您管理和查询 Memgraph 数据库。
-
下载 Memgraph Lab:
- 访问 Memgraph 下载页面。
- 选择 Memgraph Lab 并下载适用于您操作系统的版本。
-
安装并运行 Memgraph Lab:
- 安装下载的 Memgraph Lab 软件包。
- 启动 Memgraph Lab,并连接到运行中的 Memgraph 数据库。
3. 使用 Python 客户端连接 Memgraph
如果您希望通过 Python 代码与 Memgraph 交互,可以使用 Neo4j 的 Python 客户端库。
-
安装 Python 客户端库:
- 在终端中运行以下命令安装 Neo4j Python 客户端库:
pip install neo4j
- 在终端中运行以下命令安装 Neo4j Python 客户端库:
-
创建 Python 脚本:
- 创建一个新的 Python 文件,例如
memgraph_conn.py
,并添加以下代码以连接到 Memgraph:
- 创建一个新的 Python 文件,例如
from neo4j import GraphDatabase# Define correct URI and AUTH arguments (no AUTH by default)
URI = "bolt://localhost:7687"
AUTH = ("", "")with GraphDatabase.driver(URI, auth=AUTH) as client:# Check the connectionclient.verify_connectivity()# Create a user in the databaserecords, summary, keys = client.execute_query("CREATE (u:User {name: $name, password: $password}) RETURN u.name AS name;",name="John",password="pass",database_="memgraph",)# Get the resultfor record in records:print(record["name"])# Print the query countersprint(summary.counters)# Find a user John in the databaserecords, summary, keys = client.execute_query("MATCH (u:User {name: $name}) RETURN u.name AS name",name="John",database_="memgraph",)# Get the resultfor record in records:print(record["name"])# Print the queryprint(summary.query)
run MATCH (n) RETURN n
in your lab:
通过以上步骤,您可以成功安装并运行 Memgraph,并通过 Memgraph Lab 或 Python 客户端与数据库进行交互。
参考链接:https://memgraph.com/docs/client-libraries/python