Queries
Examples of Cypher queries and commands that can be used to create and manage multiple active databases.
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 |
1. Show the status of a specific database
SHOW DATABASE
neo4j@system> SHOW DATABASE neo4j;
In standalone mode:
+-----------------------------------------------------------------------------------------------+ | name | address | role | requestedStatus | currentStatus | error | default | +-----------------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "standalone" | "online" | "online" | "" | TRUE | +-----------------------------------------------------------------------------------------------+ 1 row available after 100 ms, consumed after another 6 ms
Or in a Causal Cluster:
+-----------------------------------------------------------------------------------------------+ | name | address | role | requestedStatus | currentStatus | error | default | +-----------------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "leader" | "online" | "online" | "" | TRUE | | "neo4j" | "localhost:7688" | "follower" | "online" | "online" | "" | TRUE | | "neo4j" | "localhost:7689" | "follower" | "online" | "online" | "" | TRUE | +-----------------------------------------------------------------------------------------------+ 3 row available after 100 ms, consumed after another 6 ms
2. Show the status of all databases
SHOW DATABASES
neo4j@system> SHOW DATABASES;
In standalone mode:
+------------------------------------------------------------------------------------------------+ | name | address | role | requestedStatus | currentStatus | error | default | +------------------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "standalone" | "online" | "online" | "" | TRUE | | "system" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | +------------------------------------------------------------------------------------------------+ 2 rows available after 5 ms, consumed after another 1 ms
Or in a Causal Cluster:
+------------------------------------------------------------------------------------------------+ | name | address | role | requestedStatus | currentStatus | error | default | +------------------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "leader" | "online" | "online" | "" | TRUE | | "neo4j" | "localhost:7688" | "follower" | "online" | "online" | "" | TRUE | | "neo4j" | "localhost:7689" | "follower" | "online" | "online" | "" | TRUE | | "system" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | | "system" | "localhost:7688" | "leader" | "online" | "online" | "" | FALSE | | "system" | "localhost:7689" | "follower" | "online" | "online" | "" | 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.
3. 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 | address | role | requestedStatus | currentStatus | error | +-------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "standalone" | "online" | "online" | "" | +-------------------------------------------------------------------------------------+ 1 row available after 57 ms, consumed after another 2 ms
Or in a Causal Cluster:
+-------------------------------------------------------------------------------------+ | name | address | role | requestedStatus | currentStatus | error | +-------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "follower" | "online" | "online" | "" | | "neo4j" | "localhost:7688" | "leader" | "online" | "online" | "" | | "neo4j" | "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 |
4. 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 | address | role | requestedStatus | currentStatus | error | default | +------------------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "standalone" | "online" | "online" | "" | TRUE | | "system" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | | "sales" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | +------------------------------------------------------------------------------------------------+ 3 rows available after 4 ms, consumed after another 1 ms
Or in a Causal Cluster:
+------------------------------------------------------------------------------------------------+ | name | address | role | requestedStatus | currentStatus | error | default | +------------------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "leader" | "online" | "online" | "" | TRUE | | "neo4j" | "localhost:7688" | "follower" | "online" | "online" | "" | TRUE | | "neo4j" | "localhost:7689" | "follower" | "online" | "online" | "" | TRUE | | "system" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | | "system" | "localhost:7688" | "leader" | "online" | "online" | "" | FALSE | | "system" | "localhost:7689" | "follower" | "online" | "online" | "" | FALSE | | "sales" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | | "sales" | "localhost:7688" | "follower" | "online" | "online" | "" | FALSE | | "sales" | "localhost:7689" | "leader" | "online" | "online" | "" | FALSE | +------------------------------------------------------------------------------------------------+ 9 rows available after 4 ms, consumed after another 1 ms
6. 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 | address | role | requestedStatus | currentStatus | error | default | +------------------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "standalone" | "online" | "online" | "" | TRUE | | "system" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | | "sales" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | +------------------------------------------------------------------------------------------------+ 3 rows available after 2 ms, consumed after another 2 ms
Or in a Causal Cluster:
+------------------------------------------------------------------------------------------------+ | name | address | role | requestedStatus | currentStatus | error | default | +------------------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "leader" | "online" | "online" | "" | TRUE | | "neo4j" | "localhost:7688" | "follower" | "online" | "online" | "" | TRUE | | "neo4j" | "localhost:7689" | "follower" | "online" | "online" | "" | TRUE | | "system" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | | "system" | "localhost:7688" | "leader" | "online" | "online" | "" | FALSE | | "system" | "localhost:7689" | "follower" | "online" | "online" | "" | FALSE | | "sales" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | | "sales" | "localhost:7688" | "follower" | "online" | "online" | "" | FALSE | | "sales" | "localhost:7689" | "leader" | "online" | "online" | "" | 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
7. 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 | address | role | requestedStatus | currentStatus | error | default | +------------------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "standalone" | "online" | "online" | "" | TRUE | | "system" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | | "sales" | "localhost:7687" | "standalone" | "offline" | "offline" | "" | FALSE | +------------------------------------------------------------------------------------------------+ 3 rows available after 2 ms, consumed after another 1 ms
Or in a Causal Cluster:
+------------------------------------------------------------------------------------------------+ | name | address | role | requestedStatus | currentStatus | error | default | +------------------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "leader" | "online" | "online" | "" | TRUE | | "neo4j" | "localhost:7688" | "follower" | "online" | "online" | "" | TRUE | | "neo4j" | "localhost:7689" | "follower" | "online" | "online" | "" | TRUE | | "system" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | | "system" | "localhost:7688" | "leader" | "online" | "online" | "" | FALSE | | "system" | "localhost:7689" | "follower" | "online" | "online" | "" | FALSE | | "sales" | "localhost:7687" | "unknown" | "offline" | "offline" | "" | FALSE | | "sales" | "localhost:7688" | "unknown" | "offline" | "offline" | "" | FALSE | | "sales" | "localhost:7689" | "unknown" | "offline" | "offline" | "" | 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]>
8. 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 | address | role | requestedStatus | currentStatus | error | default | +------------------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "standalone" | "online" | "online" | "" | TRUE | | "system" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | | "sales" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | +------------------------------------------------------------------------------------------------+ 3 rows available after 2 ms, consumed after another 1 ms
Or in a Causal Cluster:
+------------------------------------------------------------------------------------------------+ | name | address | role | requestedStatus | currentStatus | error | default | +------------------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "leader" | "online" | "online" | "" | TRUE | | "neo4j" | "localhost:7688" | "follower" | "online" | "online" | "" | TRUE | | "neo4j" | "localhost:7689" | "follower" | "online" | "online" | "" | TRUE | | "system" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | | "system" | "localhost:7688" | "leader" | "online" | "online" | "" | FALSE | | "system" | "localhost:7689" | "follower" | "online" | "online" | "" | FALSE | | "sales" | "localhost:7687" | "follower" | "online" | "online" | "" | FALSE | | "sales" | "localhost:7688" | "follower" | "online" | "online" | "" | FALSE | | "sales" | "localhost:7689" | "leader" | "online" | "online" | "" | FALSE | +------------------------------------------------------------------------------------------------+ 9 rows available after 2 ms, consumed after another 1 ms
9. 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 | address | role | requestedStatus | currentStatus | error | default | +------------------------------------------------------------------------------------------------+ | "neo4j" | "localhost:7687" | "standalone" | "online" | "online" | "" | TRUE | | "system" | "localhost:7687" | "standalone" | "online" | "online" | "" | FALSE | +------------------------------------------------------------------------------------------------+ 2 rows available after 6 ms, consumed after another 0 ms
Was this page helpful?