database 如何在 Neo4j 中删除/创建数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4498523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 07:58:58  来源:igfitidea点击:

How to delete/create databases in Neo4j?

databaseneo4jnodessql-deleterelationships

提问by rmv

Is it possible to create/delete different databases in the graph database Neo4jlike in MySQL? Or, at least, how to delete all nodes and relationships of an existing graph to get a clean setup for tests, e.g., using shell commands similar to rmrelor rm?

是否可以像在 MySQL 中一样在图形数据库Neo4j 中创建/删除不同的数据库?或者,至少,如何删除现有图形的所有节点和关系以获得干净的测试设置,例如,使用类似于rmrel或 的shell 命令rm

采纳答案by Peter Neubauer

You can just remove the entire graph directory with rm -rf, because Neo4j is not storing anything outside that:

您可以使用 删除整个图形目录rm -rf,因为 Neo4j 不存储任何内容:

rm -rf data/*

Also, you can of course iterate through all nodes and delete their relationships and the nodes themselves, but that might be too costly just for testing ...

此外,您当然可以遍历所有节点并删除它们的关系和节点本身,但这对于测试来说可能太昂贵了......

回答by John Bachir

even more simple command to delete all nodes and relationships:

删除所有节点和关系的更简单的命令:

MATCH (n)
OPTIONAL MATCH (n)-[r]-()
DELETE n,r

回答by Somnath Muluk

From Neo4j 2.3,

从 Neo4j 2.3 开始,

We can delete all nodes with relationships,

我们可以删除所有有关系的节点

MATCH (n)
DETACH DELETE n

Currently there is no any option to create multiple databases in Noe4j. You need to make multiple stores of Neo4j data. See reference.

目前没有任何选项可以在 Noe4j 中创建多个数据库。您需要对 Neo4j 数据进行多个存储。见参考

回答by Bharathiraja

Creating new Database in Neo4j

在 Neo4j 中创建新数据库

Before Starting neo4j community click the browse option

在启动 neo4j 社区之前单击浏览选项

enter image description here

在此处输入图片说明

and choose a different directory

并选择一个不同的目录

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

and click start button.

并单击开始按钮。

enter image description here

在此处输入图片说明

New database created on that direcory

在该目录上创建的新数据库

回答by Scott

quick and dirty way that works fine:

快速而肮脏的方式可以正常工作:

bin/neo4j stop
rm -rf data/
mkdir data
bin/neo4j start

回答by Matt Luongo

For anyone else who needs a clean graph to run a test suite - https://github.com/jexp/neo4j-clean-remote-db-addonis a great extension to allow clearing the db through a REST call. Obviously, though, don't use it in production!

对于需要干净图来运行测试套件的任何其他人 - https://github.com/jexp/neo4j-clean-remote-db-addon是一个很好的扩展,允许通过 REST 调用清除数据库。但是,显然不要在生产中使用它!

回答by Pramod

Run your test code on a different neo4j instance.

在不同的 neo4j 实例上运行您的测试代码。

  1. Copy your neo4j directory into a new location. Use this for testing. cd into the new directory.
  2. Change the port so that you can run your tests and use it normally simultaneously. To change the port open conf/neo4j-server.propertiesand set org.neo4j.server.webserver.portto an unused one.
  3. Start the test server on setup. Do ./neo4j stopand rm -rf data/graph.dbon teardown.
  1. 将您的 neo4j 目录复制到新位置。使用它进行测试。cd 进入新目录。
  2. 更改端口,以便您可以运行测试并同时正常使用它。更改端口打开conf/neo4j-server.properties并设置org.neo4j.server.webserver.port为未使用的端口。
  3. 在设置时启动测试服务器。做./neo4j stoprm -rf data/graph.db拆解。

For more details see neo4j: How to Switch Database?and the docs.

有关更多详细信息,请参阅neo4j:如何切换数据库?文档

回答by user3194532

Easiest answer is: NO

最简单的答案是:NO

The best way to "start over" is to

“重新开始”的最佳方式是

  • move to another empty data folder
  • 移动到另一个空数据文件夹

or

或者

  • close Neo4j completely
  • empty the old data folder
  • restart Neo4j and set the empty folder as the data folder
  • 完全关闭 Neo4j
  • 清空旧数据文件夹
  • 重启 Neo4j 并将空文件夹设置为数据文件夹

There is a way to delete all nodes and relationships (as described here)

有一种方法来删除所有节点和关系(如描述这里

MATCH (n)
OPTIONAL MATCH (n)-[r]-()
DELETE n,r

回答by charles

In Neo4j 2.0.0 the ? is no longer supported. Use OPTIONAL MATCH instead:

在 Neo4j 2.0.0 中?不再支持。使用 OPTIONAL MATCH 代替:

START n=node(*)
OPTIONAL MATCH (n)-[r]-()
delete n,r;

回答by Antony

As of version 3 I believe it is now possible to create separate database instances and thus their location is slightly different.

从版本 3 开始,我相信现在可以创建单独的数据库实例,因此它们的位置略有不同。

Referring to:https://neo4j.com/developer/guide-import-csv/

参考:https: //neo4j.com/developer/guide-import-csv/

The --into retail.db is obviously the target database, which must not contain an existing database.

--into retail.db 显然是目标数据库,它不能包含现有数据库。

On my Ubuntu box the location is in:

在我的 Ubuntu 盒子上,位置在:

/var/lib/neo4j/data/databaseswhere I currently see only graph.dbwhich I believe must be the default.

/var/lib/neo4j/data/databases我目前只看到graph.db我认为必须是默认值的地方。