How to reset / clear / delete neo4j database? How to reset / clear / delete neo4j database? database database

How to reset / clear / delete neo4j database?


Shut down your Neo4j server, do a rm -rf data/graph.db and start up the server again. This procedure completely wipes your data, so handle with care.


run both commands.

match (a) -[r] -> () delete a, r

above command will delete all nodes with relationships. then run ,

match (a) delete a

and it will delete nodes that have no relationships.


Dealing with multiple databases.

According to Neo4j manage multiple databases documentation:

One final administrative difference is how to completely clean out one database without impacting the entire instance with multiple databases. When dealing with a single instance and single database approach, users can delete the entire instance and start fresh. However, with multiple databases, we cannot do that unless we are comfortable losing everything from our other databases in that instance.The approach is similar to other DBMSs where we can drop and recreate the database, but retain everything else. Cypher’s command for this is CREATE OR REPLACE DATABASE <name>. This will create the database (if it does not already exist) or replace an existing database with a clean one.

When neo4j is initiated, it is possible to access two databases, a system database and a default (neo4j) database. To clear/reset neo4j database:

1 - Switch to system database:

:use system

2 - Show all databases created with the instance:

SHOW DATABASES

3 - Run the command to clear the database.

CREATE OR REPLACE DATABASE <name>