Queries
For detailed information on Cypher administrative commands, see Cypher Manual → Database management. |
All commands and example queries in this section are run in the Neo4j Cypher Shell command-line interface (CLI). Note that the |
Show the status of a specific database
SHOW DATABASE
neo4j@system> SHOW DATABASE neo4j;
In standalone mode:
+--------------------------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | default | home | +--------------------------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | TRUE | TRUE | +--------------------------------------------------------------------------------------------------------------------------------+ 1 row available after 100 ms, consumed after another 6 ms
Or in a Causal Cluster:
+--------------------------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | default | home | +--------------------------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "leader" | "online" | "online" | "" | TRUE | TRUE | | "neo4j" | [] | "read-write" | "localhost:7688" | "follower" | "online" | "online" | "" | TRUE | TRUE | | "neo4j" | [] | "read-write" | "localhost:7689" | "follower" | "online" | "online" | "" | TRUE | TRUE | +--------------------------------------------------------------------------------------------------------------------------------+ 3 row available after 100 ms, consumed after another 6 ms
Show the status of all databases
SHOW DATABASES
neo4j@system> SHOW DATABASES;
In standalone mode:
+---------------------------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | default | home | +---------------------------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | TRUE | TRUE | | "system" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | FALSE | +---------------------------------------------------------------------------------------------------------------------------------+ 2 rows available after 5 ms, consumed after another 1 ms
Or in a Causal Cluster:
+---------------------------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | default | home | +---------------------------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "leader" | "online" | "online" | "" | TRUE | TRUE | | "neo4j" | [] | "read-write" | "localhost:7688" | "follower" | "online" | "online" | "" | TRUE | TRUE | | "neo4j" | [] | "read-write" | "localhost:7689" | "follower" | "online" | "online" | "" | TRUE | TRUE | | "system" | [] | "read-write" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "system" | [] | "read-write" | "localhost:7688" | "leader" | "online" | "online" | "" | FALSE | FALSE | | "system" | [] | "read-write" | "localhost:7689" | "follower" | "online" | "online" | "" | FALSE | FALSE | +---------------------------------------------------------------------------------------------------------------------------------+ 6 rows available after 5 ms, consumed after another 1 ms
Switching between online
and offline
states is achieved using the START DATABASE
and STOP DATABASE
commands.
Show the status of the default database
The config setting dbms.default_database
defines which database is created and started by default when Neo4j starts.
The default value of this setting is neo4j
.
SHOW DEFAULT DATABASE
neo4j@system> SHOW DEFAULT DATABASE;
In standalone mode:
+--------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | +--------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | +--------------------------------------------------------------------------------------------------------------+ 1 row available after 57 ms, consumed after another 2 ms
Or in a Causal Cluster:
+--------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | +--------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "follower" | "online" | "online" | "" | | "neo4j" | [] | "read-write" | "localhost:7688" | "leader" | "online" | "online" | "" | | "neo4j" | [] | "read-write" | "localhost:7689" | "follower" | "online" | "online" | "" | +--------------------------------------------------------------------------------------------------------------+ 3 row available after 57 ms, consumed after another 2 ms
You can change the default database by using dbms.default_database
, and restarting the server.
In Community Edition, the default database is the only database available, other than the |
Create a database
CREATE DATABASE
neo4j@system> CREATE DATABASE sales;
0 rows available after 108 ms, consumed after another 0 ms
neo4j@system> SHOW DATABASES;
In standalone mode:
+---------------------------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | default | home | +---------------------------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | TRUE | TRUE | | "system" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | FALSE | +---------------------------------------------------------------------------------------------------------------------------------+ 3 rows available after 4 ms, consumed after another 1 ms
Or in a Causal Cluster:
+---------------------------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | default | home | +---------------------------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "leader" | "online" | "online" | "" | TRUE | TRUE | | "neo4j" | [] | "read-write" | "localhost:7688" | "follower" | "online" | "online" | "" | TRUE | TRUE | | "neo4j" | [] | "read-write" | "localhost:7689" | "follower" | "online" | "online" | "" | TRUE | TRUE | | "system" | [] | "read-write" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "system" | [] | "read-write" | "localhost:7688" | "leader" | "online" | "online" | "" | FALSE | FALSE | | "system" | [] | "read-write" | "localhost:7689" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7688" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7689" | "leader" | "online" | "online" | "" | FALSE | FALSE | +---------------------------------------------------------------------------------------------------------------------------------+ 9 rows available after 4 ms, consumed after another 1 ms
Create or replace a database
CREATE OR REPLACE DATABASE
neo4j@sales> match (n) return count(n) as countNode;
+-----------+ | countNode | +-----------+ | 115 | +-----------+ 1 row available after 12 ms, consumed after another 0 ms
neo4j@system> CREATE OR REPLACE DATABASE sales;
0 rows available after 64 ms, consumed after another 0 ms
neo4j@system> SHOW DATABASES;
In standalone mode:
+---------------------------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | default | home | +---------------------------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | TRUE | TRUE | | "system" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | FALSE | +---------------------------------------------------------------------------------------------------------------------------------+ 3 rows available after 2 ms, consumed after another 2 ms
Or in a Causal Cluster:
+---------------------------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | default | home | +---------------------------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "leader" | "online" | "online" | "" | TRUE | TRUE | | "neo4j" | [] | "read-write" | "localhost:7688" | "follower" | "online" | "online" | "" | TRUE | TRUE | | "neo4j" | [] | "read-write" | "localhost:7689" | "follower" | "online" | "online" | "" | TRUE | TRUE | | "system" | [] | "read-write" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "system" | [] | "read-write" | "localhost:7688" | "leader" | "online" | "online" | "" | FALSE | FALSE | | "system" | [] | "read-write" | "localhost:7689" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7688" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7689" | "leader" | "online" | "online" | "" | FALSE | FALSE | +---------------------------------------------------------------------------------------------------------------------------------+ 9 rows available after 2 ms, consumed after another 2 ms
neo4j@system> :use sales
neo4j@sales> match (n) return count(n) as countNode;
+-----------+ | countNode | +-----------+ | 0 | +-----------+ 1 row available after 15 ms, consumed after another 1 ms
Stop a database
STOP DATABASE
neo4j@system> STOP DATABASE sales;
0 rows available after 18 ms, consumed after another 6 ms
neo4j@system> SHOW DATABASES;
In standalone mode:
+---------------------------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | default | home | +---------------------------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | TRUE | TRUE | | "system" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7687" | "standalone" | "offline" | "offline" | "" | FALSE | FALSE | +---------------------------------------------------------------------------------------------------------------------------------+ 3 rows available after 2 ms, consumed after another 1 ms
Or in a Causal Cluster:
+---------------------------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | default | home | +---------------------------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "leader" | "online" | "online" | "" | TRUE | TRUE | | "neo4j" | [] | "read-write" | "localhost:7688" | "follower" | "online" | "online" | "" | TRUE | TRUE | | "neo4j" | [] | "read-write" | "localhost:7689" | "follower" | "online" | "online" | "" | TRUE | TRUE | | "system" | [] | "read-write" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "system" | [] | "read-write" | "localhost:7688" | "leader" | "online" | "online" | "" | FALSE | FALSE | | "system" | [] | "read-write" | "localhost:7689" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7687" | "unknown" | "offline" | "offline" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7688" | "unknown" | "offline" | "offline" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7689" | "unknown" | "offline" | "offline" | "" | FALSE | FALSE | +---------------------------------------------------------------------------------------------------------------------------------+ 9 rows available after 2 ms, consumed after another 1 ms
neo4j@system> :use sales
Unable to get a routing table for database 'sales' because this database is unavailable neo4j@sales[UNAVAILABLE]>
Start a database
START DATABASE
neo4j@sales[UNAVAILABLE]> :use system
neo4j@system> START DATABASE sales;
0 rows available after 21 ms, consumed after another 1 ms
neo4j@system> SHOW DATABASES;
In standalone mode:
+---------------------------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | default | home | +---------------------------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | TRUE | TRUE | | "system" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | FALSE | +---------------------------------------------------------------------------------------------------------------------------------+ 3 rows available after 2 ms, consumed after another 1 ms
Or in a Causal Cluster:
+---------------------------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | default | home | +---------------------------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "leader" | "online" | "online" | "" | TRUE | TRUE | | "neo4j" | [] | "read-write" | "localhost:7688" | "follower" | "online" | "online" | "" | TRUE | TRUE | | "neo4j" | [] | "read-write" | "localhost:7689" | "follower" | "online" | "online" | "" | TRUE | TRUE | | "system" | [] | "read-write" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "system" | [] | "read-write" | "localhost:7688" | "leader" | "online" | "online" | "" | FALSE | FALSE | | "system" | [] | "read-write" | "localhost:7689" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7688" | "follower" | "online" | "online" | "" | FALSE | FALSE | | "sales" | [] | "read-write" | "localhost:7689" | "leader" | "online" | "online" | "" | FALSE | FALSE | +---------------------------------------------------------------------------------------------------------------------------------+ 9 rows available after 2 ms, consumed after another 1 ms
Drop or remove a database
DROP DATABASE
neo4j@system> DROP DATABASE sales;
0 rows available after 82 ms, consumed after another 1 ms
neo4j@system> SHOW DATABASES;
+---------------------------------------------------------------------------------------------------------------------------------+ | name | aliases | access | address | role | requestedStatus | currentStatus | error | default | home | +---------------------------------------------------------------------------------------------------------------------------------+ | "neo4j" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | TRUE | TRUE | | "system" | [] | "read-write" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | FALSE | +---------------------------------------------------------------------------------------------------------------------------------+ 2 rows available after 6 ms, consumed after another 0 ms