neo4j对于数据库的读取导入和导出Dump and load databases

https://neo4j.com/docs/operations-manual/current/tools/dump-load/

 

Dump and load databases

neo4j-admin dump --database=<database> --to=<destination-path>

neo4j-admin load --from=<archive-path> --database=<database> [--force]

 

Dump the database called graph.db into a file called /backups/graph.db/2016-10-02.dump. The destination directory for the dump file — in this case /backups/graph.db — must exist before calling the command.

$neo4j-home> bin/neo4j-admin dump --database=graph.db --to=/backups/graph.db/2016-10-02.dump

$neo4j-home> ls /backups/graph.db

$neo4j-home> 2016-10-02.dump

Load the backed-up database contained in the file /backups/graph.db/2016-10-02.dump into database graph.db. Since we have a database running, we first have to shut it down. When we use the --force option, any existing database gets overwritten.

$neo4j-home> bin/neo4j stop

Stopping Neo4j.. stopped

$neo4j-home> bin/neo4j-admin load --from=/backups/graph.db/2016-10-02.dump --database=graph.db --force
### 使用 APOC 库将 MySQL 数据导入Neo4j数据库 #### 准备工作 确保安装并配置好 Neo4j MySQL。下载适合 Neo4j 版本的 `apoc` 插件以及 `mysql-connector-java` 驱动程序[^2]。 对于 Neo4j 3.4.6 版本,应使用对应的 APOC 3.4.0.1 版本以避免兼容性问题导致的服务不可用情况发生[^3]。 #### 创建连接字符串 定义用于访问 MySQL 的 JDBC 连接 URL、用户名密码: ```cypher CALL apoc.config.set('apoc.jdbc.url', 'jdbc:mysql://localhost:3306/your_database?user=your_user&password=your_password') ``` 此命令设置全局参数来简化后续调用中的连接信息输入[^1]。 #### 加载表结构至节点与关系模式 假设有一个名为 `users` 的表格,其中包含字段 id, name, age;另一个关联表叫作 friendships 表示用户之间的友谊关系,则可以通过如下方式创建相应的图模型: ```cypher // 清除已有数据 (仅限测试环境) MATCH (n) DETACH DELETE n; // 将 users 表转换成节点 CALL apoc.load.jdbc("SELECT * FROM users", "users") YIELD row AS userRecord CREATE (:User { userId: toInteger(userRecord.id), userName: userRecord.name, userAge :toInteger(userRecord.age) }); // 建立 friendship 关系 CALL apoc.load.jdbc("SELECT from_id,to_id FROM friendships", "friendships") YIELD row as friendPair WITH friendPair.from_id AS sourceId, friendPair.to_id AS targetId MATCH (source: User {userId: toInteger(sourceId)}), (target: User {userId: toInteger(targetId)}) MERGE (source)-[:FRIEND]->(target); ``` 上述脚本首先清除了现有数据(适用于开发环境中),接着通过两次 SQL 查询分别构建了代表用户的节点集及其间的社交联系边集合。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值