Querying with mgconsole
The easiest way to execute Cypher queries against Memgraph is by using Memgraph's command-line tool, mgconsole.
1. Install mgconsole
If you installed Memgraph Platform with the Docker image
(memgraph/memgraph-platform
), mgconsole will start automatically when you run
the container. Skip the installation steps and continue with executing
Cypher queries.
If you want to install mgconsole to query a running Memgraph database instance, follow the installation steps.
- Docker 🐳
- Windows
- macOS
- Linux
1. If you installed Memgraph DB using Docker, you can run the client from your
Docker image. First, you need to find the CONTAINER_ID
of your Memgraph
container:
docker ps
2. Once you know the CONTAINER_ID
, find the IP address of the container by
executing:
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' CONTAINER_ID
3. Now, you can start mgconsole by running the following command:
docker run -it --entrypoint=mgconsole memgraph --host CONTAINER_IP
1. Download mgconsole from the Download Hub.
2. From PowerShell, start mgconsole with the command:
./mgconsole --host HOST --port PORT
If Memgraph is running locally using the default configuration, start mgconsole with:
./mgconsole --host 127.0.0.1 --port 7687
1. Download mgconsole from the Download Hub.
2. From the terminal, provide execution permission to the current user:
chmod u+x ./mgconsole
3. Start mgconsole with the command:
./mgconsole --host HOST --port PORT
If Memgraph is running locally using the default configuration, start mgconsole with:
./mgconsole --host 127.0.0.1 --port 7687
We will soon release a downloadable Debian package, so you don't have to install mgconsole from source.
1. Follow the instructions on how to build and install mgconsole from source.
2. Start mgconsole with the command:
./mgconsole --host HOST --port PORT
If Memgraph is running locally using the default configuration, start mgconsole with:
./mgconsole --host 127.0.0.1 --port 7687
2. Execute a Cypher query
After the client has started, it should present a command prompt similar to:
mgconsole X.X
Connected to 'memgraph://127.0.0.1:7687'
Type :help for shell usage
Quit the shell by typing Ctrl-D(eof) or :quit
memgraph>
At this point, it is possible to execute Cypher queries against a running Memgraph database instance.
You can use the TAB
key to autocomplete commands in mgconsole.
Each query needs to end with the ;
(semicolon) character. For example:
CREATE (u:User {name: "Alice"})-[:Likes]->(m:Software {name: "Memgraph"});
The above query will create 2 nodes in the database, one labeled "User" with name "Alice" and the other labeled "Software" with name "Memgraph". It will also create a relationship that "Alice" likes "Memgraph".
To find created nodes and relationships, execute the following query:
MATCH (u:User)-[r]->(x) RETURN u, r, x;
Where to next?
If you want to learn more about graph databases and Cypher queries, visit Memgraph Playground and go through the guided lessons. All the datasets and most of the queries used in the guided lessons can also be explored in the Tutorials section, and knowledge about Cypher is gathered in the Cypher manual.
If you are all good to go on your own - import your data!