Basic Use Cypher Shell Linux - tomgeudens/practical-neo4j GitHub Wiki
Context: The Neo4j Cypher Shell is a commandline client application for the Neo4j database. Like the Neo4j Browser it allows you to run queries against the database. Unlike the Neo4j Browser it has no fancy visualization of the results and can be used both interactively and in a pipeline. While the Neo4j Cypher Shell can be installed on its own, this document will assume you did a Setup Neo4j Enterprise on Linux (4.3) or a Setup Neo4j Enterprise on Mac (4.3).
Last Update: 2021/07/11 - update to 4.3.2
The installations mentioned above create a neo4j folder somewhere on your system and put the database and assorted (correct Java, plugins, ...) in there as well.
If you have the database running in console mode (as those installations recommend), you should at this point open a second terminal window and in that one also position yourself in that same folder. Everything that follows will go from that assumption!
Verify you are in the right spot
<user>@<machine>:~/neo4j$ . ./scripts/environment.sh
<user>@<machine>:~/neo4j$ ls -l $NEO4J_HOME/bin/tools/cypher-shell.jar
22158426 cypher-shell.jar
Everything that follows will also assume you executed the environment script and the NEO4J_HOME environment variable is set!
As stated before, the Neo4j Cypher Shell is a standalone client tool and thus can be used to connect to any remote Neo4j instance that exposes it's bolt port. In this document however we are not going to bother with remote connections.
A basic interactive connection to the default database on an instance
<user>@<machine>:~/neo4j$ $NEO4J_HOME/bin/cypher-shell -u neo4j -p trinity
Connected to Neo4j <version> at <connection url> as user neo4j.
> :quit
Bye!
<user>@<machine>:~/neo4j$
Note that there is a slight difference between connecting to a 3.x database and connecting to a 4.x database. The former did not have the concept of multiple database per instance and thus you get no indication of that. The latter does and with the above command you'd connect to the default database (most of the time neo4j) in the instance.
A basic interactive connection to the system database on an instance (4.x) only
<user>@<machine>:~/neo4j$ $NEO4J_HOME/bin/cypher-shell -u neo4j -p trinity -d system
Connected to Neo4j <version> at <connection url> as user neo4j.
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 |
+------------------------------------------------------------------------------------------------+
neo4j@system> :quit
Bye!
<user>@<machine>:~/neo4j$
Some things you can do without data in the database ...
<user>@<machine>:~/neo4j$ $NEO4J_HOME/bin/cypher-shell -u neo4j -p trinity
Connected to Neo4j <version> at <connection url> as user neo4j.
> RETURN apoc.version();
> RETURN gds.version();
> CALL apoc.help('load') YIELD name RETURN name;
> :quit
Bye!
<user>@<machine>:~/neo4j$
Some things you can do without data in the database ...
<user>@<machine>:~/neo4j$ $NEO4J_HOME/bin/cypher-shell -u neo4j -p trinity "RETURN apoc.version();"
<user>@<machine>:~/neo4j$ echo "RETURN apoc.version();" > scripts/apocversion.cql
<user>@<machine>:~/neo4j$ cat scripts/apocversion.cql | $NEO4J_HOME/bin/cypher-shell -u neo4j -p trinity
<user>@<machine>:~/neo4j$ $NEO4J_HOME/bin/cypher-shell -u neo4j -p trinity -f scripts/apocversion.cql
<user>@<machine>:~/neo4j$ export NEO4J_USERNAME=neo4j
<user>@<machine>:~/neo4j$ export NEO4J_PASSWORD=trinity
<user>@<machine>:~/neo4j$ $NEO4J_HOME/bin/cypher-shell -f scripts/apocversion.cql