How to delete/create databases in Neo4j?

前端 未结 12 1175
既然无缘
既然无缘 2020-12-12 11:52

Is it possible to create/delete different databases in the graph database Neo4j like in MySQL? Or, at least, how to delete all nodes and relationships of an existing graph t

相关标签:
12条回答
  • 2020-12-12 12:39

    In 2.0.0 -M6 You can execute the following Cypher script to delete all nodes and relations:

    start n=node(*)
    match (n)-[r?]-()
    delete n,r
    
    0 讨论(0)
  • 2020-12-12 12:40

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

    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 ...

    0 讨论(0)
  • 2020-12-12 12:40

    Creating new Database in Neo4j

    Before Starting neo4j community click the browse option

    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

    0 讨论(0)
  • 2020-12-12 12:41

    Run your test code on a different neo4j instance.

    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.properties and set org.neo4j.server.webserver.port to an unused one.
    3. Start the test server on setup. Do ./neo4j stop and rm -rf data/graph.db on teardown.

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

    0 讨论(0)
  • 2020-12-12 12:42

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

    0 讨论(0)
  • 2020-12-12 12:44

    You can delete your data files and if you want to go through this way, I would recommend delete just your graph.db, for example. Otherwise your are going to mess your authentication info.

    0 讨论(0)
提交回复
热议问题