Basic Use Cypher Shell Windows - 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 Windows (4.3).

Last Update: 2021/07/11 - update to 4.3.2

One - Location Location Location

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 powershell window and in that one also position yourself in that same folder. Everything that follows will go from that assumption!

We'll check the size of the cypher-shell jarfile to verify we are in the right spot

PS C:\Users\<youruser>\Documents\neo4j> . .\scripts\environment.ps1
Setting the versions ... Done!
PS C:\Users\<youruser>\Documents\neo4j> dir .\neo4j-enterprise-4.3.2\bin\tools\cypher-shell.jar
22158426 cypher-shell.jar

Everything that follows will assume you executed the environment script!

Two - Connecting to an instance, connecting to a database

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

PS C:\Users\<youruser>\Documents\neo4j> .\neo4j-enterprise-4.3.2\bin\cypher-shell.bat -u neo4j -p trinity
Connected to Neo4j using Bolt protocol version 4.2 at neo4j://localhost:7687 as user neo4j.
Type :help for a list of available commands or :exit to exit the shell.
Note that Cypher queries must end with a semicolon.

neo4j@neo4j> :quit

Bye!
PS C:\Users\<youruser>\Documents\neo4j>

A basic interactive connection to the system database on an instance

PS C:\Users\<youruser>\Documents\neo4j> .\neo4j-enterprise-4.3.2\bin\cypher-shell.bat -u neo4j -p trinity -d system
Connected to Neo4j using Bolt protocol version 4.2 at neo4j://localhost:7687 as user neo4j.
Type :help for a list of available commands or :exit to exit the shell.
Note that Cypher queries must end with a semicolon.

neo4j@system> SHOW DATABASES;

neo4j@system> :quit

Bye!

Three - Interactive querying

Some things you can do without data in the database ...

PS C:\Users\<youruser>\Documents\neo4j> .\neo4j-enterprise-4.3.2\bin\cypher-shell.bat -u neo4j -p trinity
Connected to Neo4j using Bolt protocol version 4.2 at neo4j://localhost:7687 as user neo4j.
Type :help for a list of available commands or :exit to exit the shell.
Note that Cypher queries must end with a semicolon.

neo4j@neo4j> RETURN apoc.version();
neo4j@neo4j> RETURN gds.version();
neo4j@neo4j> CALL apoc.help('load') YIELD name RETURN name;

neo4j@neo4j> :quit

Bye!

Four - Pipeline

Some things you can do without data in the database ...

PS C:\Users\<youruser>\Documents\neo4j> .\neo4j-enterprise-4.3.2\bin\cypher-shell.bat -u neo4j -p trinity "RETURN apoc.version();"

PS C:\Users\<youruser>\Documents\neo4j> echo "RETURN apoc.version();" > scripts\apocversion.cql
PS C:\Users\<youruser>\Documents\neo4j> type .\scripts\apocversion.cql | .\neo4j-enterprise-4.3.2\bin\cypher-shell.bat -u neo4j -p trinity

PS C:\Users\<youruser>\Documents\neo4j> .\neo4j-enterprise-4.3.2\bin\cypher-shell.bat -u neo4j -p trinity -f .\scripts\apocversion.cql

PS C:\Users\<youruser>\Documents\neo4j> $Env:NEO4J_USERNAME = "neo4j"
PS C:\Users\<youruser>\Documents\neo4j> $Env:NEO4J_PASSWORD = "trinity"
PS C:\Users\<youruser>\Documents\neo4j> .\neo4j-enterprise-4.3.2\bin\cypher-shell.bat -f .\scripts\apocversion.cql
⚠️ **GitHub.com Fallback** ⚠️